worker-swarm
TypeScript icon, indicating that this package has built-in type declarations

2.0.3 • Public • Published

Worker Swarm

A small library to help distribute work across a pool of workers

npm i worker-swarm

worker.js

self.onmessage = (e) => {
  self.postMessage({
    jobId: e.data.jobId, // send the job id back to complete a task
    message: 'RESPONSE FROM ANOTHER THREAD'
  })
}

UI Thread

import { WorkerSwarm } from 'worker-swarm';

// Create 3 instances of the worker
const swarm = new WorkerSwarm(() => new Worker('./worker.js'), 3);

// Will go to first worker
swarm.post({}).then((res) => {
    console.log(res)
});

// Will go to the second worker
swarm.post({}).then((res) => {
    console.log(res)
});

// Will go to the third worker
swarm.post({}).then((res) => {
    console.log(res)
});

Readme

Keywords

none

Package Sidebar

Install

npm i worker-swarm

Weekly Downloads

4

Version

2.0.3

License

ISC

Unpacked Size

6.13 kB

Total Files

8

Last publish

Collaborators

  • deebloo