https://github.com/nairihar/nodejs-threads
Additional layer for Node.js worker_threads
https://github.com/nairihar/nodejs-threads
nodejs threads
Last synced: 4 months ago
JSON representation
Additional layer for Node.js worker_threads
- Host: GitHub
- URL: https://github.com/nairihar/nodejs-threads
- Owner: nairihar
- Created: 2018-08-03T15:06:16.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-08-03T15:15:10.000Z (over 7 years ago)
- Last Synced: 2025-05-30T07:48:01.841Z (7 months ago)
- Topics: nodejs, threads
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Node.js Threads
Additional layer for Node.js worker_threads
Thread's run function takes an callback as argument, and runs it in a thread. It returns a promise, inside callback you can return promise or plain value(i.e. object, string and etc...).
### Example
```javascript
const Thread = require('./Thread');
Thread.run(() => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('Hello');
}, 3000);
})
})
.then(res => {
console.log(`Success: ${res}`);
})
.catch(err => {
console.log(err);
});
```