0.4.1 • Published 2 months ago

@solid-primitives/workers v0.4.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

@solid-primitives/workers

size size stage

A set of utility to support using Web Workers and Shared Workers:

createWorker - Provides a getter and setter for the primitive.

createWorkerPool - Creates a pool of workers and round-robins requests between each.

createSignaledWorker - Creates a work with that reads and writes to signals.

How to use it

createWorker

Create a basic web worker:

const [worker, start, stop] = createWorker(function add(a, b) {
  return a + b;
});
console.log(await worker.add(1, 2));
// output: 3

createWorkerPool

Create a worker pool with a set concurrency:

const [pool, start, stop] = createWorkerPool(4, function add(a, b) {
  return a + b;
});
console.log(await pool.add(1, 2));
// output: 3

createSignaledWorker

Create a more advanced worker that accepts multiple instructional inputs:

const [input, setInput] = createSignal([1, 1]);
const [output, setOutput] = createSignal([1, 1]);
createSignaledWorker({
  input,
  output: setOutput,
  func: function add([a, b]) {
    return a + b;
  },
});
setInput([1, 2]);
console.log(output());
// output: 3

Demo

You may view a working example here: link to Stackblize or CodeSandBox

Changelog

See CHANGELOG.md

Inspiration

Inspired by Jason Miller's worker function. Borrows the RPC and function export method.

0.4.1

2 months ago

0.4.0

5 months ago

0.3.0

10 months ago

0.2.7

1 year ago

0.2.6

1 year ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.3

2 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.160

4 years ago

0.0.150

4 years ago

0.0.100

4 years ago