An open API service indexing awesome lists of open source software.

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

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);
});
```