@pooley/core
v1.0.1
Published
Generic pool implementation that works with Webworkers, Promises, etc.
Downloads
106
Readme
@pooley/core
Generic pool implementation that works with Webworkers, Promises, etc.
Requires a specific worker processor, queue and a scaler to excute.
See other packages for a suitable implementations.
Install
Install the library:
npm install @pooley/core
Usage
import { WorkerPool, WorkerTask, WorkerPoolEvent } from '@pooley/core';
// Create some task that should process a pool queue
const task: WorkerTask<string, Promise<string>> = (data) => {
return new Promise((res) => setTimeout(() => res(data), 1000));
};
// Create a pool with a task and suitable queue/scaler/processor
const pool = new WorkerPool({
task,
queue,
poolScaler,
processorFactory,
});
// Listen to a processed data from the pool
pool.on(WorkerPoolEvent.Data, (ev) => this.log('Pool data: ', ev.data));
// Or wait when it's finished
await pool.once(WorkerPoolEvent.Empty);
Building
Run nx build core
to build the library.
Running unit tests
Run nx test core
to execute the unit tests via Jest.