Skip to main content

Class: SharedWorkerPool

A pool of web workers that can be used to execute jobs. The pool will create workers up to the maximum number of workers specified in the options. When a job is queued, the pool will find the first available worker and execute the job. If no workers are available, the job will be queued until a worker becomes available.

Constructors

constructor

new SharedWorkerPool(Proto, options?): SharedWorkerPool

Create a new worker pool.

Parameters

NameTypeDefault valueDescription
Proto() => SharedWorkerundefinedThe worker class to create.
optionsSharedWorkerPoolOptionsdefaultOptionsThe options to create the worker pool.

Returns

SharedWorkerPool

Properties

Proto

Proto: () => SharedWorker

Type declaration

new Proto(): SharedWorker

The worker class to create.

Returns

SharedWorker


WORKING_COUNT

Static WORKING_COUNT: number = 0

A static count of working web workers across all worker pools.


options

options: SharedWorkerPoolOptions = defaultOptions

The options to create the worker pool.


queue

queue: SharedWorkerPoolJob[] = []

The queue of jobs that are waiting to be executed.

Accessors

isBusy

get isBusy(): boolean

Whether or not are there no available workers.

Returns

boolean


workingCount

get workingCount(): number

The number of workers that are simultaneously working.

Returns

number

Methods

addJob

addJob(job): void

Append a new job to be executed by a worker.

Parameters

NameTypeDescription
jobSharedWorkerPoolJobThe job to queue.

Returns

void