@pooley/promise
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@pooley/promise

Implements Promise-based processor for @pooley/core.

@pooley/promise

Allows to execute tasks in a pool using Promises to wait for the completion of the tasks.

Note: All tasks are executed on the same main thread and any blocking operations will block entire pool and everything else - so make sure you are using non-blocking operations inside your tasks!

Install

Install the library with it's core peer dependency:

npm install @pooley/promise @pooley/core

Usage

import { WorkerPool } from '@pooley/core';
import { PromiseWorkerProcessorFactory } from '@pooley/promise';

// Create a task that returns a Promise
const task: WorkerTask<string, Promise<string>> = (data) => {
  return new Promise((res) => setTimeout(() => res(data), 1000));
};

// Create a pool with promise processor factory
const pool = new WorkerPool({
  task,
  queue,
  poolScaler,
  processorFactory: new PromiseWorkerProcessorFactory(),
});

Building

Run nx build promise to build the library.

Running unit tests

Run nx test promise to execute the unit tests via Jest.

Readme

Keywords

none

Package Sidebar

Install

npm i @pooley/promise

Weekly Downloads

51

Version

1.0.1

License

MIT

Unpacked Size

7.64 kB

Total Files

13

Last publish

Collaborators

  • gund