X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=docs%2Fclasses%2FDynamicThreadPool.html;h=02e1b442e92a7705258996de8b9e4622c676ec49;hb=e39450c0889208d6dcde666fc05b95fe7a98ee29;hp=6910150bf4dd6529111bb2ca763a2a2770729168;hpb=d0f1dce33156fdb99f0ca3627839001909419497;p=poolifier.git diff --git a/docs/classes/DynamicThreadPool.html b/docs/classes/DynamicThreadPool.html index 6910150b..02e1b442 100644 --- a/docs/classes/DynamicThreadPool.html +++ b/docs/classes/DynamicThreadPool.html @@ -1,57 +1,665 @@ -DynamicThreadPool | poolifier
Options
All
  • Public
  • Public/Protected
  • All
Menu

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, an event is emitted. If you want to listen to this event, use the pool's emitter.

-
template DataType

of data sent to the worker. This can only be serializable data.

-
template ResponseType

of response of execution. This can only be serializable data.

-
author

Alessandro Pio Ardizio

-
since

0.0.1

-

Type parameters

  • Data = unknown

  • Response = unknown

Hierarchy

Index

Constructors

constructor

Properties

Optional Readonly emitter

emitter?: PoolEmitter

Readonly filePath

filePath: string

Readonly max

max: number

Protected nextMessageId

nextMessageId: number = 0
-

Id of the next message.

-

Readonly numberOfWorkers

numberOfWorkers: number

Readonly opts

Protected promiseMap

promiseMap: Map<number, PromiseWorkerResponseWrapper<ThreadWorkerWithMessageChannel, Response>> = ...
-

The promise map.

-

Readonly tasks

tasks: Map<ThreadWorkerWithMessageChannel, number> = ...

Protected workerChoiceStrategyContext

workerChoiceStrategyContext: WorkerChoiceStrategyContext<ThreadWorkerWithMessageChannel, Data, Response>
-

Worker choice strategy instance implementing the worker choice algorithm.

-

Default to a strategy implementing a round robin algorithm.

-

Readonly workers

Accessors

busy

  • get busy(): boolean

numberOfRunningTasks

  • get numberOfRunningTasks(): number

type

  • get type(): PoolType

Methods

Protected afterWorkerSetup

Protected chooseWorker

Protected createAndSetupWorker

Protected createWorker

Protected decreaseWorkersTasks

destroy

  • destroy(): Promise<void>

destroyWorker

execute

  • execute(data: Data): Promise<Response>

findFreeTasksMapEntry

Protected increaseWorkersTask

Protected internalExecute

Protected internalGetBusyStatus

  • internalGetBusyStatus(): boolean

Protected isMain

  • isMain(): boolean

registerWorkerMessageListener

  • registerWorkerMessageListener<Message>(messageChannel: ThreadWorkerWithMessageChannel, listener: (message: MessageValue<Message, unknown>) => void): void

Protected removeWorker

Protected sendToWorker

setWorkerChoiceStrategy

  • setWorkerChoiceStrategy(workerChoiceStrategy: "ROUND_ROBIN" | "LESS_RECENTLY_USED"): void

Protected setupHook

  • setupHook(): void

Protected workerListener

  • workerListener(): (message: MessageValue<Response, unknown>) => void
  • -

    This function is the listener registered for each worker.

    -

    Returns (message: MessageValue<Response, unknown>) => void

    The listener function to execute when a message is sent from a worker.

    -
      • (message: MessageValue<Response, unknown>): void
      • -

        This function is the listener registered for each worker.

        -

        Parameters

        • message: MessageValue<Response, unknown>

        Returns void

        The listener function to execute when a message is sent from a worker.

        -

Generated using TypeDoc

\ No newline at end of file + +
+ +
filePath: string
+

Path to the worker-file.

+
+
+ +
max: number
+

Maximum number of threads that can be created by this pool.

+
+
+ +
numberOfWorkers: number
+

Number of workers that this pool should manage.

+
+
+ +
opts: PoolOptions<ThreadWorkerWithMessageChannel>
+

Options for the pool.

+
+
+ +
promiseResponseMap: Map<string, PromiseResponseWrapper<ThreadWorkerWithMessageChannel, Response>> = ...
+

The execution response promise map.

+ +

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

+
+
+ +
workerChoiceStrategyContext: WorkerChoiceStrategyContext<ThreadWorkerWithMessageChannel, Data, Response>
+

Worker choice strategy context referencing a worker choice algorithm implementation.

+

Default to a round robin algorithm.

+
+
+ +
workerNodes: WorkerNode<ThreadWorkerWithMessageChannel, Data>[] = []
+

Pool worker nodes.

+
+
+

Accessors

+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+

Methods

+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+

Generated using TypeDoc

+
\ No newline at end of file