Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rksm/simple-nodejs-workers
Using child_process.fork easily.
https://github.com/rksm/simple-nodejs-workers
Last synced: about 1 month ago
JSON representation
Using child_process.fork easily.
- Host: GitHub
- URL: https://github.com/rksm/simple-nodejs-workers
- Owner: rksm
- Created: 2014-05-17T23:55:02.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-05-18T00:13:27.000Z (over 10 years ago)
- Last Synced: 2024-10-13T10:25:57.766Z (3 months ago)
- Language: JavaScript
- Size: 133 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# simple-nodejs-workers [![Build Status](https://travis-ci.org/rksm/simple-nodejs-workers.svg?branch=master)](https://travis-ci.org/rksm/simple-nodejs-workers)
child_process.fork interface for easily multi-threading tasks in nodejs.
## Usage
```js
var workers = require('simple-nodejs-workers');var worker = workers.startWorker(function() {
longRunningComputation(function whenDone() {
// do whatever you want in here, it runs in another thread.
// NOTE! Using closed values form outside the startWorker call will not
// work since this code is just stringified over to the worker
process.send({computationResult: 42});
});
});// called once worker is started
worker.once("start", function() {
console.log('Worker started');
});// called once worker is done
worker.once('close', function() {
console.log('Worker finished');
});// will be called with msg == {computationResult: 42}
worker.on('message', function(msg) {
console.log('Worker send:', msg);
}
```