poolifier - v5.1.0
    Preparing search index...

    Class DynamicThreadPool<Data, Response>

    A thread pool with a dynamic number of threads, but a guaranteed minimum number of threads.

    This thread pool creates new threads when the others are busy, up to the maximum number of threads. When the maximum number of threads is reached and workers are busy, an event is emitted. If you want to listen to this event, use the pool's emitter.

    0.0.1

    Type Parameters

    • Data = unknown

      Type of data sent to the worker. This can only be structured-cloneable data.

    • Response = unknown

      Type of execution response. This can only be structured-cloneable data.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    destroying: boolean

    Whether the pool is destroying or not.

    emitter?: EventEmitterAsyncResource
    filePath: string

    Path to the worker file.

    maximumNumberOfWorkers?: number

    Maximum number of workers that this pool manages.

    minimumNumberOfWorkers: number

    Minimum number of workers that this pool manages.

    opts: PoolOptions<Worker>

    Options for the pool.

    promiseResponseMap: Map<
        `${string}-${string}-${string}-${string}-${string}`,
        PromiseResponseWrapper<Response>,
    > = ...

    The task execution response promise map:

    • key: The message id of each submitted task.
    • value: An object that contains task's worker node key, execution response promise resolve and reject callbacks, async resource.

    When we receive a message from the worker, we get a map entry with the promise resolve/reject bound to the message id.

    started: boolean

    Whether the pool is started or not.

    starting: boolean

    Whether the pool is starting or not.

    workerChoiceStrategiesContext?: WorkerChoiceStrategiesContext<
        Worker,
        Data,
        Response,
    >

    Worker choice strategies context referencing worker choice algorithms implementation.

    workerNodes: IWorkerNode<Worker, Data>[] = []

    Accessors

    • get backPressure(): boolean

      Whether the pool is back pressured or not.

      Returns boolean

      The pool back pressure boolean status.

    • get busy(): boolean

      Whether the pool is busy or not.

      Returns boolean

      The pool busyness boolean status.

    • get type(): "fixed" | "dynamic"

      The pool type.

      If it is 'dynamic', it provides the max property.

      Returns "fixed" | "dynamic"

    • get worker(): "cluster" | "thread"

      The worker type.

      Returns "cluster" | "thread"

    Methods

    • Parameters

      • Optionaldata: Data
      • Optionalname: string
      • OptionalabortSignal: AbortSignal
      • OptionaltransferList: readonly Transferable[]

      Returns Promise<Response>

    • Parameters

      • data: Iterable<Data>
      • Optionalname: string
      • OptionalabortSignals: Iterable<AbortSignal, any, any>
      • OptionaltransferList: readonly Transferable[]

      Returns Promise<Response[]>

    • Sends a message to worker given its worker node key.

      Parameters

      • workerNodeKey: number

        The worker node key.

      • message: MessageValue<Data>

        The message.

      • OptionaltransferList: readonly Transferable[]

        The optional array of transferable objects.

      Returns void

    • Parameters

      • workerChoiceStrategy:
            | "FAIR_SHARE"
            | "INTERLEAVED_WEIGHTED_ROUND_ROBIN"
            | "LEAST_BUSY"
            | "LEAST_ELU"
            | "LEAST_USED"
            | "ROUND_ROBIN"
            | "WEIGHTED_ROUND_ROBIN"
      • OptionalworkerChoiceStrategyOptions: WorkerChoiceStrategyOptions

      Returns void