A very simple function based implementation of node.js worker threads
🏠 Homepage
✨ Demo
npm install nodejs-threads
// No need to create a separate file for the worker thread.
const { runInWorker } = require('nodejs-threads');
// OR
import { runInWorker } from 'nodejs-threads';
// Assume this is the CPU intensive task
const { calculateScore } = './users.service';
async function main() {
try {
// Spawn a worker thread like this:
// Does not block the main thread
const result = await runInWorker('./users.service', 'calculateScore', { name: 'Karan' });
console.log('[PRIMARY] : WORKER EXECUTED WITH ...', result);
} catch (error) {
console.log('[PRIMARY] : ERROR', error);
}
}
For complete usage guide, refer our API.md file
npm run test
👤 Karan Raina [email protected]
- Website: https://karanraina.tech/
- Twitter: @karankraina
- Github: @karankraina
- LinkedIn: @karankraina
Contributions, issues and feature requests are welcome!
Feel free to check issues page. You can also take a look at the contributing guide.
Give a ⭐️ if this project helped you!
Copyright © 2021 Karan Raina [email protected].
This project is MIT licensed.
This README was generated with ❤️ by readme-md-generator