X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=docs%2Fclasses%2Ffixedthreadpool.html;h=b7019f27a2dc4b867f232824643f81e272c37c72;hb=4f4ae1cb3c33228a023ea599c2648268d15e6c0f;hp=65c94585e3c1ab1cd4fb641df03fe75219247a55;hpb=7c0ba92006a5c188738ffc5ff642c51f172df3d6;p=poolifier.git diff --git a/docs/classes/fixedthreadpool.html b/docs/classes/fixedthreadpool.html index 65c94585..b7019f27 100644 --- a/docs/classes/fixedthreadpool.html +++ b/docs/classes/fixedthreadpool.html @@ -1,1185 +1,55 @@ - - - - - - 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.

-

This pool selects the threads in a round robin fashion.

-
-
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 response of execution. This can only be serializable data.

    -
    -
    -
  • -
-
-
-

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

      Options for this fixed thread pool. Default: {}

      -
      -
    • -
    -

    Returns FixedThreadPool<Data, Response>

    -
  • -
-
-
-
-

Properties

-
- -

Optional Readonly emitter

-
emitter: undefined | PoolEmitter
- -
-
-
inheritdoc
-
-
-
-
-
- -

Readonly filePath

-
filePath: string
- -
-
- -

Optional Readonly max

-
max: undefined | 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.
  • -
-

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

        Parameters

        -
          -
        • -
          message: MessageValue<Response, unknown>
          -
        • -
        -

        Returns void

        -
      • -
      -
    • -
    -
  • -
-
-
-
- -
-
- -
-

Generated using TypeDoc

-
-
- - - \ No newline at end of file +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.

+

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

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