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

https://github.com/karankraina/nodejs-threads

A very simple function based implementation of node.js worker threads
https://github.com/karankraina/nodejs-threads

clustering nodejs npm threads worker-threads

Last synced: 5 months ago
JSON representation

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

Awesome Lists containing this project

README

          

Welcome to nodejs-threads 👋




Version


Version


Documentation


Maintenance


License: MIT


Twitter: karankraina

> 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 **

* 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!
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 ](https://github.com/karankraina).

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)_