UNPKG

nodejs-threads

Version:

A very simple functiobn based implementation of node.js worker threads

97 lines (68 loc) • 3.27 kB
<h1 align="center">Welcome to nodejs-threads šŸ‘‹</h1> <p> <a href="https://circleci.com/gh/karankraina/nodejs-threads/tree/main.svg?style=svg" target="_blank"> <img alt="Version" src="https://circleci.com/gh/karankraina/nodejs-threads/tree/main.svg?style=svg"> </a> <a href="https://www.npmjs.com/package/nodejs-threads" target="_blank"> <img alt="Version" src="https://img.shields.io/npm/v/nodejs-threads.svg"> </a> <a href="https://github.com/karankraina/nodejs-threads#readme" target="_blank"> <img alt="Documentation" src="https://img.shields.io/badge/documentation-yes-brightgreen.svg" /> </a> <a href="https://github.com/karankraina/nodejs-threads/graphs/commit-activity" target="_blank"> <img alt="Maintenance" src="https://img.shields.io/badge/Maintained%3F-yes-green.svg" /> </a> <a href="https://github.com/karankraina/nodejs-threads/blob/main/LICENSE" target="_blank"> <img alt="License: MIT" src="https://img.shields.io/github/license/karankraina/nodejs-threads" /> </a> <a href="https://twitter.com/karankraina" target="_blank"> <img alt="Twitter: karankraina" src="https://img.shields.io/twitter/follow/karankraina.svg?style=social" /> </a> </p> > A very simple function based implementation of node.js worker threads ### šŸ  [Homepage](https://github.com/karankraina/nodejs-threads#readme) ### ✨ [Demo](https://replit.com/@karankraina/nodejs-threads) ## Install ```sh npm install nodejs-threads ``` ## Basic Usage ```javascript // 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); } } ``` ## API Guide For complete usage guide, refer our [API.md](https://github.com/karankraina/nodejs-threads/blob/main/API.md) file ## Run tests ```sh npm run test ``` ## Author šŸ‘¤ **Karan Raina <karanraina1996@gmail.com>** * Website: https://karanraina.tech/ * Twitter: [@karankraina](https://twitter.com/karankraina) * Github: [@karankraina](https://github.com/karankraina) * LinkedIn: [@karankraina](https://linkedin.com/in/karankraina) ## šŸ¤ Contributing Contributions, issues and feature requests are welcome!<br />Feel free to check [issues page](https://github.com/karankraina/nodejs-threads/issues). You can also take a look at the [contributing guide](https://github.com/karankraina/nodejs-threads/blob/main/CONTRIBUTING.md). ## Show your support Give a ā­ļø if this project helped you! ## šŸ“ License Copyright Ā© 2021 [Karan Raina <karanraina1996@gmail.com>](https://github.com/karankraina).<br /> This project is [MIT](https://github.com/karankraina/nodejs-threads/blob/main/LICENSE) licensed. *** _This README was generated with ā¤ļø by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_