sw

spawn-worker

Spawn a web worker with a function

Showing:

Popularity

Downloads/wk

18

Maintenance

No Maintenance Data Available

Package

Dependencies

0

Size (min+gzip)

0.3KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

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 worker
  • count Number of workers, Optional, Default: 1
  • Return: single or multiple instances of Worker

License

MIT

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100