1.0.1 • Published 3 years ago

@pooley/core v1.0.1

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

@pooley/core

Generic pool implementation that works with Webworkers, Promises, etc.

@pooley/core

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.

1.0.1

3 years ago

1.0.0

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago