spawn-worker
v1.0.0
Published
Spawn a web worker with a function
Downloads
22
Readme
spawn-worker
Spawn a web worker with a function
Install
$ npm i spawn-worker
Usage
const spawn = require('spawn-worker');
// Single worker
const worker = spawn(function() {
postMessage('Yo!');
self.close();
});
worker.onmessage = function(event) {
console.log(event.data); // 'Yo!'
};
// Multiple workers
const workers = spawn(function() {
postMessage('Yo!');
self.close();
}, 2);
workers.forEach(function(worker) {
worker.onmessage = function(event) {
console.log(event.data); // 'Yo!'
};
});
API
spawn(function[, count])
function
Function to be executed inside of a workercount
Number of workers, Optional, Default: 1- Return: single or multiple instances of
Worker
License
MIT