X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=docs%2Fclasses%2FDynamicThreadPool.html;h=267078cc65897c6734582acee4e6f1e00f0eddfb;hb=3aaed019abde0022e986c1db05db9d5d7bc76594;hp=6910150bf4dd6529111bb2ca763a2a2770729168;hpb=d0f1dce33156fdb99f0ca3627839001909419497;p=poolifier.git diff --git a/docs/classes/DynamicThreadPool.html b/docs/classes/DynamicThreadPool.html index 6910150b..267078cc 100644 --- a/docs/classes/DynamicThreadPool.html +++ b/docs/classes/DynamicThreadPool.html @@ -1,57 +1,677 @@ -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. +DynamicThreadPool | poolifier

+
+ +
+
+
+
+ +

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.

-
+
+

Type Parameters

+
    +
  • +

    Data = unknown

    +

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

    +
  • +
  • +

    Response = unknown

    +

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

    +
+
+

Hierarchy

+
+
+
+
+ +
+
+

Constructors

+
+ +
+
+

Properties

+
+ +
emitter?: PoolEmitter
+
+

Inherit Doc

+
+ +
filePath: string
+
+ +
max: number
+
+ +
nextMessageId: number = 0
+

Id of the next message.

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

The promise map.

+
  • key: This is the message Id of each submitted task.
  • value: An object that contains the worker, the resolve function and the reject function.

When we receive a message from the worker we get a map entry and resolve/reject the promise based on the message.

-

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
+
+ +
workerChoiceStrategyContext: WorkerChoiceStrategyContext<ThreadWorkerWithMessageChannel, Data, Response>
+

Worker choice strategy instance implementing the worker choice algorithm.

+

Default to a strategy implementing a round robin algorithm.

+
+
+ + +
+

Inherit Doc

+
+ +
workersTasksUsage: Map<ThreadWorkerWithMessageChannel, TasksUsage> = ...
+
+

Inherit Doc

+
+

Accessors

+
+ +
+
+ +
    +
  • get numberOfRunningTasks(): number
  • +
  • +
    +

    Inherit Doc

    +

    Returns number

+
+ +
+
+

Methods

+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
    + +
  • +
    +

    Inherit Doc

    +
    +

    Parameters

    +
      +
    • +
      workerChoiceStrategy: "ROUND_ROBIN" | "LESS_RECENTLY_USED" | "FAIR_SHARE" | "WEIGHTED_ROUND_ROBIN"
    +

    Returns void

+
+ +
    + +
  • +

    Setup hook that can be overridden by a Poolifier pool implementation to run code before workers are created in the abstract constructor.

    -

Returns void

Protected workerListener

Generated using TypeDoc

\ No newline at end of file + +

Returns void

+
+ +
+ +
+

Generated using TypeDoc

+
\ No newline at end of file