2.0.3 • Published 3 years ago

worker-swarm v2.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

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)
});
2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.0-5

4 years ago

1.0.0-4

4 years ago

1.0.0-6

4 years ago

1.0.0-3

4 years ago

1.0.0-1

4 years ago

0.0.1

4 years ago