1.0.1 • Published 1 year ago

@pooley/webworker v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

@pooley/webworker

Implements Webworker-based processor for @pooley/core.

@pooley/webworker

Allows to execute tasks in a pool using Webworkers to fully parallelize pool processing.

Note: Since a task is executed in a different thread it cannot use any scoped variables from it's original thread as they will not exist in a Webworker thread - so use task arguments to pass all the nesessary data into a task.

Install

Install the library with it's core peer dependency:

npm install @pooley/webworker @pooley/core

Usage

import { WorkerPool } from '@pooley/core';
import { WebWorkerProcessor } from '@pooley/webworker';

// Create a task that will be executed in a WebWorker
const task: WorkerTask<string, string> = (data) => {
  while (Date.now() - start < 1000) {
    // Fully blocking the thread is fine here...
  }
  return data;
};

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

Building

Run nx build webworker to build the library.

Running unit tests

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

1.0.1

1 year ago

1.0.0

1 year ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago