X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=docs%2Fclasses%2FFixedThreadPool.html;h=4fe8d4d8294782ccb3938f560acc16bb1fa607aa;hb=e39450c0889208d6dcde666fc05b95fe7a98ee29;hp=de188c51b7a27b2207d87e0a875aafdb1fcd1642;hpb=d0f1dce33156fdb99f0ca3627839001909419497;p=poolifier.git diff --git a/docs/classes/FixedThreadPool.html b/docs/classes/FixedThreadPool.html index de188c51..4fe8d4d8 100644 --- a/docs/classes/FixedThreadPool.html +++ b/docs/classes/FixedThreadPool.html @@ -1,55 +1,654 @@ -FixedThreadPool | poolifier
Options
All
  • Public
  • Public/Protected
  • All
Menu

Class FixedThreadPool<Data, Response>

-

A thread pool with a fixed number of threads.

-

It is possible to perform tasks in sync or asynchronous mode as you prefer.

+FixedThreadPool | poolifier
+
+ +
+
+
+
+ +

Class FixedThreadPool<Data, Response>

+
+

A thread pool with a fixed number of threads.

+

It is possible to perform tasks in sync or asynchronous mode as you prefer.

This pool selects the threads in a round robin fashion.

-
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

  • -

    Constructs a new poolifier fixed thread pool.

    -

    Type parameters

    • Data = unknown

    • Response = unknown

    Parameters

    • numberOfThreads: number
      -

      Number of threads for this pool.

      -
    • filePath: string
      -

      Path to an implementation of a ThreadWorker file, which can be relative or absolute.

      -
    • opts: PoolOptions<ThreadWorkerWithMessageChannel> = {}

    Returns FixedThreadPool<Data, Response>

Properties

Optional Readonly emitter

emitter?: PoolEmitter
inheritdoc

Readonly filePath

filePath: string

Optional Readonly max

max?: number
inheritdoc

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.

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

    Author

    Alessandro Pio Ardizio

    + +

    Since

    0.0.1

    +
+
+

Type Parameters

+
    +
  • +

    Data = unknown

    +

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

    +
  • +
  • +

    Response = unknown

    +

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

    +
+
+

Hierarchy

+
+
+
+
+ +
+
+

Constructors

+
+ +
+
+

Properties

+
+ +
emitter?: PoolEmitter
+

Emitter on which events can be listened to.

+

Events that can currently be listened to:

+
    +
  • 'full': Emitted when the pool is dynamic and full.
  • +
  • 'busy': Emitted when the pool is busy.
-

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> = ...
inheritdoc

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

inheritdoc

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

    Type parameters

    • Message

    Parameters

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

          • message: MessageValue<Message, unknown>

          Returns void

    Returns void

Protected removeWorker

Protected sendToWorker

setWorkerChoiceStrategy

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

    Parameters

    • workerChoiceStrategy: "ROUND_ROBIN" | "LESS_RECENTLY_USED"

    Returns void

Protected setupHook

  • setupHook(): 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

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

+
+
+ +
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