X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=docs%2Fclasses%2FThreadWorker.html;h=2d4283dd70efaeb071882ba75d0c0dea4394144f;hb=2a6631992868d900762f62e4c228dce4e4ee549a;hp=e90d1519081252311b951ac183d40e05f15c6822;hpb=d0f1dce33156fdb99f0ca3627839001909419497;p=poolifier.git diff --git a/docs/classes/ThreadWorker.html b/docs/classes/ThreadWorker.html index e90d1519..2d4283dd 100644 --- a/docs/classes/ThreadWorker.html +++ b/docs/classes/ThreadWorker.html @@ -1,83 +1,602 @@ -ThreadWorker | poolifier
Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ThreadWorker<Data, Response>

-

A thread worker used by a poolifier ThreadPool.

-

When this worker is inactive for more than the given maxInactiveTime, +ThreadWorker | poolifier

+
+ +
+
+
+
+ +

Class ThreadWorker<Data, Response>

+
+

A thread worker used by a poolifier ThreadPool.

+

When this worker is inactive for more than the given maxInactiveTime, it will send a termination request to its main thread.

If you use a DynamicThreadPool the extra workers that were created will be terminated, but the minimum number of workers will be guaranteed.

-
template DataType

of data this worker receives from pool's execution. This can only be serializable data.

-
template ResponseType

of response the worker sends back to the main thread. 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 thread worker.

    -

    Type parameters

    • Data = unknown

    • Response = unknown

    Parameters

    • fn: (data: Data) => Response
      -

      Function processed by the worker when the pool's execution function is invoked.

      -
        • (data: Data): Response
        • Parameters

          • data: Data

          Returns Response

    • opts: WorkerOptions = {}
      -

      Options for the worker.

      -

    Returns ThreadWorker<Data, Response>

Properties

Protected Optional Readonly aliveInterval

aliveInterval?: Timeout
-

Handler Id of the aliveInterval worker alive check.

-

Protected lastTaskTimestamp

lastTaskTimestamp: number
-

Timestamp of the last task processed by this worker.

-

Protected mainWorker

mainWorker: undefined | null | MessagePort

Readonly opts

opts: WorkerOptions = ...

Methods

asyncId

  • asyncId(): number
  • Returns number

    The unique asyncId assigned to the resource.

    -

bind

  • bind<Func>(fn: Func): Func & { asyncResource: AsyncResource }
  • -

    Binds the given function to execute to this AsyncResource's scope.

    -

    The returned function will have an asyncResource property referencing -the AsyncResource to which the function is bound.

    -
    since

    v14.8.0, v12.19.0

    -

    Type parameters

    • Func: (...args: any[]) => any

    Parameters

    • fn: Func
      -

      The function to bind to the current AsyncResource.

      -

    Returns Func & { asyncResource: AsyncResource }

Protected checkAlive

  • checkAlive(): void

emitDestroy

+
+

Type Parameters

+
    +
  • +

    Data = unknown

    +

    Type of data this worker receives from pool's execution. This can only be structured-cloneable data.

    +
    +
  • +
  • +

    Response = unknown

    +

    Type of response the worker sends back to the main thread. This can only be structured-cloneable data.

    +
    +
+
+

Hierarchy

+
+
+
+
+ +
+
+

Constructors

+
+ +
+
+

Properties

+
+ +
aliveInterval?: Timeout
+

Handler id of the aliveInterval worker alive check.

+
+
+
+ +
isMain: boolean
+

Whether this is the main worker or not.

+
+
+
+ +
lastTaskTimestamp: number
+

Timestamp of the last task processed by this worker.

+
+
+
+ +
mainWorker: MessagePort
+

Reference to main worker.

+
+
+
+ +
opts: WorkerOptions = ...
+

Options for the worker.

+
+
+
+ +
statistics: WorkerStatistics
+

Performance statistics computation requirements.

+
+
+
+ +
taskFunctions: Map<string, WorkerFunction<Data, Response>>
+

Task function(s) processed by the worker when the pool's execution function is invoked.

+
+
+
+

Accessors

+
+ +
+
+

Methods

+
+ +
    + +
  • +

    Returns number

    The unique asyncId assigned to the resource.

    + +
+
+ +
    + +
  • +

    Binds the given function to execute to this AsyncResource's scope.

    +
    +
    +

    Type Parameters

    +
      +
    • +

      Func extends ((...args) => any)

    +
    +

    Parameters

    +
      +
    • +
      fn: Func
      +

      The function to bind to the current AsyncResource.

      +
      +
    +

    Returns Func

    +
    +

    Since

    v14.8.0, v12.19.0

    +
+
+ +
+
+ +
    + +
  • +

    Call all destroy hooks. This should only ever be called once. An error will be thrown if it is called more than once. This must be manually called. If the resource is left to be collected by the GC then the destroy hooks will never be called.

    -

Returns ThreadWorker<Data, Response>

A reference to asyncResource.

-

Protected getMainWorker

  • getMainWorker(): MessagePort

Protected handleError

  • handleError(e: string | Error): string

Protected run

  • run(fn: (data?: Data) => Response, value: MessageValue<Data, unknown>): void
  • -

    Run the given function synchronously.

    -

    Parameters

    • fn: (data?: Data) => Response
      -

      Function that will be executed.

      -
        • (data?: Data): Response
        • Parameters

          • Optional data: Data

          Returns Response

    • value: MessageValue<Data, unknown>
      -

      Input data for the given function.

      -

    Returns void

Protected runAsync

  • runAsync(fn: (data?: Data) => Promise<Response>, value: MessageValue<Data, unknown>): void
  • -

    Run the given function asynchronously.

    -

    Parameters

    • fn: (data?: Data) => Promise<Response>
      -

      Function that will be executed.

      -
        • (data?: Data): Promise<Response>
        • Parameters

          • Optional data: Data

          Returns Promise<Response>

    • value: MessageValue<Data, unknown>
      -

      Input data for the given function.

      -

    Returns void

runInAsyncScope

  • runInAsyncScope<This, Result>(fn: (...args: any[]) => Result, thisArg?: This, ...args: any[]): Result
  • -

    Call the provided function with the provided arguments in the execution context +

    +

    Returns ThreadWorker<Data, Response>

    A reference to asyncResource.

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

    Handles an error and convert it to a string so it can be sent back to the main worker.

    +
    +
    +

    Parameters

    +
      +
    • +
      e: string | Error
      +

      The error raised by the worker.

      +
      +
    +

    Returns string

    The error message.

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

    Call the provided function with the provided arguments in the execution context of the async resource. This will establish the context, trigger the AsyncHooks before callbacks, call the function, trigger the AsyncHooks after callbacks, and then restore the original execution context.

    -
    since

    v9.6.0

    -

Type parameters

Parameters

Returns Result

Protected sendToMainWorker

triggerAsyncId

Static bind

Generated using TypeDoc

\ No newline at end of file + +
+

Type Parameters

+
+
+

Parameters

+
+

Returns Result

+
+

Since

v9.6.0

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

Generated using TypeDoc

+
\ No newline at end of file