Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/poolifier/src/mod.ts>IPool

Fast and small web worker pool
Latest
interface IPool
import { type IPool } from "https://deno.land/x/poolifier@v0.3.14/src/mod.ts";

Contract definition for a poolifier pool.

Type Parameters

Worker extends IWorker
optional
Data = unknown
optional
Response = unknown

Properties

readonly
info: PoolInfo

Pool information.

readonly
workerNodes: Array<IWorkerNode<Worker, Data>>

Pool worker nodes.

readonly
optional
eventTarget: EventTarget

Pool event target.

Events that can currently be listened to:

  • 'ready': Emitted when the number of workers created in the pool has reached the minimum size expected and are ready. If the pool is dynamic with a minimum number of workers is set to zero, this event is emitted when at least one dynamic worker is ready.
  • 'busy': Emitted when the number of workers created in the pool has reached the maximum size expected and are executing concurrently their tasks quota.
  • 'full': Emitted when the pool is dynamic and the number of workers created has reached the maximum size expected.
  • 'empty': Emitted when the pool is dynamic with a minimum number of workers set to zero and the number of workers has reached the minimum size expected.
  • 'destroy': Emitted when the pool is destroyed.
  • 'error': Emitted when an uncaught error occurs.
  • 'messageerror': Emitted when an error occurs while processing a message event.
  • 'taskError': Emitted when an error occurs while executing a task.
  • 'backPressure': Emitted when all worker nodes have back pressure (i.e. their tasks queue is full: queue size >= maximum queue size).
readonly
execute: (
data?: Data,
name?: string,
transferList?: Transferable[],
) => Promise<Response>

Executes the specified function in the worker constructor with the task data input parameter.

readonly
start: () => void

Starts the minimum number of workers in this pool.

readonly
destroy: () => Promise<void>

Terminates all workers in this pool.

readonly
hasTaskFunction: (name: string) => boolean

Whether the specified task function exists in this pool.

readonly
addTaskFunction: (name: string, fn: TaskFunction<Data, Response>) => Promise<boolean>

Adds a task function to this pool. If a task function with the same name already exists, it will be overwritten.

readonly
removeTaskFunction: (name: string) => Promise<boolean>

Removes a task function from this pool.

readonly
listTaskFunctionNames: () => string[]

Lists the names of task function available in this pool.

readonly
setDefaultTaskFunction: (name: string) => Promise<boolean>

Sets the default task function in this pool.

readonly
setWorkerChoiceStrategy: (workerChoiceStrategy: WorkerChoiceStrategy, workerChoiceStrategyOptions?: WorkerChoiceStrategyOptions) => void

Sets the worker choice strategy in this pool.

readonly
setWorkerChoiceStrategyOptions: (workerChoiceStrategyOptions: WorkerChoiceStrategyOptions) => void

Sets the worker choice strategy options in this pool.

readonly
enableTasksQueue: (enable: boolean, tasksQueueOptions?: TasksQueueOptions) => void

Enables/disables the worker node tasks queue in this pool.

readonly
setTasksQueueOptions: (tasksQueueOptions: TasksQueueOptions) => void

Sets the worker node tasks queue options in this pool.