https://github.com/pkief/nodejs-worker-threads
Demo for NodeJS WorkerThreads
https://github.com/pkief/nodejs-worker-threads
nodejs typescript worker-threads
Last synced: 4 months ago
JSON representation
Demo for NodeJS WorkerThreads
- Host: GitHub
- URL: https://github.com/pkief/nodejs-worker-threads
- Owner: PKief
- Created: 2019-09-12T19:34:02.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-09-12T19:43:25.000Z (over 5 years ago)
- Last Synced: 2025-02-02T03:51:12.959Z (4 months ago)
- Topics: nodejs, typescript, worker-threads
- Language: TypeScript
- Size: 3.91 KB
- Stars: 7
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NodeJS Worker Threads
This example demonstrates how NodeJS can use multiple threads for long running tasks. Use cases can be long running calculations, compressions or encryptions that should not block the main thread.
## Requirements
- NodeJS 10.x or NodeJS 12
## Installation
- `npm install`
- `npm run build`
- `npm start`## Additional Explanation
During the execution the index script calls the worker script and prints each second a log message to the console. In the meanwhile the worker is doing some simple calculations that cost some time. When the worker is done, the interval of log messages is stopped and the result of the sum is printed out.
```bash
[1s] Worker is working...
[2s] Worker is working...
[3s] Worker is working...
[4s] Worker is working...
[5s] Worker is working...
[6s] Worker is working...
[7s] Worker is working...
[8s] Worker is working...
[9s] Worker is working...
[10s] Worker is working...
[11s] Worker is working...
[12s] Worker is working...
[13s] Worker is working...
[14s] Worker is working...
[15s] Worker is working...
[16s] Worker is working...
[17s] Worker is working...
{ result: 5000000000, status: 'Done' }
```