poolifier - v5.0.2
    Preparing search index...

    Interface AbstractPool<Worker, Data, Response>Abstract

    Base class that implements some shared logic for all poolifier pools.

    interface AbstractPool<
        Worker extends IWorker,
        Data = unknown,
        Response = unknown,
    > {
        emitter?: EventEmitterAsyncResource;
        filePath: string;
        maximumNumberOfWorkers?: number;
        minimumNumberOfWorkers: number;
        opts: PoolOptions<Worker>;
        promiseResponseMap: Map<
            `${string}-${string}-${string}-${string}-${string}`,
            PromiseResponseWrapper<Response>,
        >;
        workerChoiceStrategiesContext?: WorkerChoiceStrategiesContext<
            Worker,
            Data,
            Response,
        >;
        workerNodes: IWorkerNode<Worker, Data>[];
        get backPressure(): boolean;
        get busy(): boolean;
        get info(): PoolInfo;
        get type(): "fixed" | "dynamic";
        get worker(): "cluster" | "thread";
        addTaskFunction(
            name: string,
            fn: TaskFunction<Data, Response> | TaskFunctionObject<Data, Response>,
        ): Promise<boolean>;
        afterTaskExecutionHook(
            workerNodeKey: number,
            message: MessageValue<Response>,
        ): void;
        afterWorkerNodeSetup(workerNodeKey: number): void;
        beforeTaskExecutionHook(workerNodeKey: number, task: Task<Data>): void;
        checkAndEmitDynamicWorkerCreationEvents(): void;
        checkAndEmitDynamicWorkerDestructionEvents(): void;
        createAndSetupDynamicWorkerNode(): number;
        createAndSetupWorkerNode(): number;
        deregisterWorkerMessageListener<Message>(
            workerNodeKey: number,
            listener: (message: MessageValue<Message>) => void,
        ): void;
        destroy(): Promise<void>;
        destroyWorkerNode(workerNodeKey: number): Promise<void>;
        enableTasksQueue(
            enable: boolean,
            tasksQueueOptions?: TasksQueueOptions,
        ): void;
        execute(
            data?: Data,
            name?: string,
            abortSignal?: AbortSignal,
            transferList?: readonly Transferable[],
        ): Promise<Response>;
        flagWorkerNodeAsNotReady(workerNodeKey: number): void;
        flushTasksQueue(workerNodeKey: number): number;
        getWorkerInfo(workerNodeKey: number): undefined | WorkerInfo;
        hasTaskFunction(name: string): boolean;
        internalBackPressure(): boolean;
        internalBusy(): boolean;
        isMain(): boolean;
        listTaskFunctionsProperties(): TaskFunctionProperties[];
        mapExecute(
            data: Iterable<Data>,
            name?: string,
            abortSignals?: Iterable<AbortSignal, any, any>,
            transferList?: readonly Transferable[],
        ): Promise<Response[]>;
        registerOnceWorkerMessageListener<Message>(
            workerNodeKey: number,
            listener: (message: MessageValue<Message>) => void,
        ): void;
        registerWorkerMessageListener<Message>(
            workerNodeKey: number,
            listener: (message: MessageValue<Message>) => void,
        ): void;
        removeTaskFunction(name: string): Promise<boolean>;
        sendStartupMessageToWorker(workerNodeKey: number): void;
        sendToWorker(
            workerNodeKey: number,
            message: MessageValue<Data>,
            transferList?: readonly Transferable[],
        ): void;
        setDefaultTaskFunction(name: string): Promise<boolean>;
        setTasksQueueOptions(
            tasksQueueOptions: undefined | TasksQueueOptions,
        ): void;
        setupHook(): void;
        setWorkerChoiceStrategy(
            workerChoiceStrategy:
                | "FAIR_SHARE"
                | "INTERLEAVED_WEIGHTED_ROUND_ROBIN"
                | "LEAST_BUSY"
                | "LEAST_ELU"
                | "LEAST_USED"
                | "ROUND_ROBIN"
                | "WEIGHTED_ROUND_ROBIN",
            workerChoiceStrategyOptions?: WorkerChoiceStrategyOptions,
        ): void;
        setWorkerChoiceStrategyOptions(
            workerChoiceStrategyOptions: undefined | WorkerChoiceStrategyOptions,
        ): boolean;
        shallCreateDynamicWorker(): boolean;
        start(): void;
        workerMessageListener(message: MessageValue<Response>): void;
    }

    Type Parameters

    • Worker extends IWorker

      Type of worker which manages this pool.

    • 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)

    Implements

    Index

    Properties

    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.

    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.

    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 type(): "fixed" | "dynamic"

      The pool type.

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

      Returns "fixed" | "dynamic"

    Methods

    • Method hooked up after a worker node has been newly created. Can be overridden.

      Parameters

      • workerNodeKey: number

        The newly created worker node key.

      Returns void

    • Hook executed before the worker task execution. Can be overridden.

      Parameters

      • workerNodeKey: number

        The worker node key.

      • task: Task<Data>

        The task to execute.

      Returns void

    • Creates a new, completely set up dynamic worker node.

      Returns number

      New, completely set up dynamic worker node key.

    • Creates a new, completely set up worker node.

      Returns number

      New, completely set up worker node key.

    • Deregisters a listener callback on the worker given its worker node key.

      Type Parameters

      • Message

      Parameters

      • workerNodeKey: number

        The worker node key.

      • listener: (message: MessageValue<Message>) => void

        The message listener callback.

      Returns void

    • Terminates the worker node given its worker node key.

      Parameters

      • workerNodeKey: number

        The worker node key.

      Returns Promise<void>

    • Parameters

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

      Returns Promise<Response>

    • Gets the worker information given its worker node key.

      Parameters

      • workerNodeKey: number

        The worker node key.

      Returns undefined | WorkerInfo

      The worker information.

    • Parameters

      • name: string

      Returns boolean

    • Whether the worker nodes are back pressured or not.

      Returns boolean

      Worker nodes back pressure boolean status.

    • Whether worker nodes are executing concurrently their tasks quota or not.

      Returns boolean

      Worker nodes busyness boolean status.

    • Returns whether the worker is the main worker or not.

      Returns boolean

      true if the worker is the main worker, false otherwise.

    • Parameters

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

      Returns Promise<Response[]>

    • Registers once a listener callback on the worker given its worker node key.

      Type Parameters

      • Message

      Parameters

      • workerNodeKey: number

        The worker node key.

      • listener: (message: MessageValue<Message>) => void

        The message listener callback.

      Returns void

    • Registers a listener callback on the worker given its worker node key.

      Type Parameters

      • Message

      Parameters

      • workerNodeKey: number

        The worker node key.

      • listener: (message: MessageValue<Message>) => void

        The message listener callback.

      Returns void

    • Parameters

      • name: string

      Returns Promise<boolean>

    • Sends the startup message to worker given its worker node key.

      Parameters

      • workerNodeKey: number

        The worker node key.

      Returns void

    • 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

      • name: string

      Returns Promise<boolean>

    • Setup hook to execute code before worker nodes are created in the abstract constructor. Can be overridden.

      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

    • Conditions for dynamic worker creation.

      Returns boolean

      Whether to create a dynamic worker or not.