nodejs-threads
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

Welcome to nodejs-threads 👋

Version Version Documentation Maintenance License: MIT Twitter: karankraina

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

🏠 Homepage

Demo

Install

npm install nodejs-threads

Basic Usage

// 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 file

Run tests

npm run test

Author

👤 Karan Raina karanraina1996@gmail.com

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page. You can also take a look at the contributing guide.

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2021 Karan Raina karanraina1996@gmail.com.
This project is MIT licensed.


This README was generated with ❤️ by readme-md-generator

/nodejs-threads/

    Package Sidebar

    Install

    npm i nodejs-threads

    Weekly Downloads

    11

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    58 kB

    Total Files

    25

    Last publish

    Collaborators

    • karankraina