X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=docs%2Fclasses%2Fabstractworker.html;h=f48b9b70f3f5f40ecdae025e9146e20b848636f9;hb=4f4ae1cb3c33228a023ea599c2648268d15e6c0f;hp=bc99b16ea7705ae246b6bfeb42351dae3a732c5a;hpb=7c0ba92006a5c188738ffc5ff642c51f172df3d6;p=poolifier.git diff --git a/docs/classes/abstractworker.html b/docs/classes/abstractworker.html index bc99b16e..f48b9b70 100644 --- a/docs/classes/abstractworker.html +++ b/docs/classes/abstractworker.html @@ -1,1008 +1,91 @@ - - - - - - AbstractWorker | poolifier - - - - - - -
-
-
-
- -
-
- Options -
-
- All -
    -
  • Public
  • -
  • Public/Protected
  • -
  • All
  • -
-
- - - - -
-
- Menu -
-
-
-
-
-
- -

Class AbstractWorker<MainWorker, Data, Response>

-
-
-
-
-
-
-
-
-
-

Base class containing some shared logic for all poolifier workers.

-
-
-
-
-

Type parameters

-
    -
  • -

    MainWorker: Worker | MessagePort

    -
    -
    -

    Type of main worker.

    -
    -
    -
  • -
  • -

    Data = unknown

    -
    -
    -

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

    -
    -
    -
  • -
  • -

    Response = unknown

    -
    -
    -

    Type of response the worker sends back to the main worker. This can only be serializable data.

    -
    -
    -
  • -
-
-
-

Hierarchy

- -
-
-

Index

-
- -
-
-
-

Constructors

-
- -

constructor

-
    -
  • new AbstractWorker<MainWorker, Data, Response>(type: string, isMain: boolean, fn: (data: Data) => Response, mainWorker?: null | MainWorker, opts?: WorkerOptions): AbstractWorker<MainWorker, Data, Response>
  • -
-
    -
  • - -
    -
    -

    Constructs a new poolifier worker.

    -
    -
    -

    Type parameters

    -
      -
    • -

      MainWorker: Worker | MessagePort

      -
    • -
    • -

      Data = unknown

      -
    • -
    • -

      Response = unknown

      -
    • -
    -

    Parameters

    -
      -
    • -
      type: string
      -
      -

      The type of async event.

      -
      -
    • -
    • -
      isMain: boolean
      -
      -

      Whether this is the main worker or not.

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

          -
        • -
        -
      • -
      -
    • -
    • -
      Optional mainWorker: null | MainWorker
      -
      -

      Reference to main worker.

      -
      -
    • -
    • -
      opts: WorkerOptions = ...
      -
      -

      Options for the worker.

      -
      -
    • -
    -

    Returns AbstractWorker<MainWorker, Data, Response>

    -
  • -
-
-
-
-

Properties

-
- -

Protected Readonly async

-
async: boolean
- -
-
-

Whether the worker is working asynchronously or not.

-
-
-
-
- -

Protected Optional Readonly interval

-
interval: undefined | Timeout
- -
-
-

Handler ID of the interval alive check.

-
-
-
-
- -

Protected Readonly killBehavior

-
killBehavior: "SOFT" | "HARD"
- -
-
-

The kill behavior set as option on the Worker constructor or a default value.

-
-
-
-
- -

Protected lastTask

-
lastTask: number
- -
-
-

Timestamp of the last task processed by this worker.

-
-
-
-
- -

Protected Optional mainWorker

-
mainWorker: undefined | null | MainWorker
- -
-
- -

Protected Readonly maxInactiveTime

-
maxInactiveTime: number
- -
-
-

The maximum time to keep this worker alive while idle. The pool automatically checks and terminates this worker when the time expires.

-
-
-
-
- -

Readonly opts

-
opts: WorkerOptions = ...
- -
-
-
-

Methods

-
- -

asyncId

-
    -
  • asyncId(): number
  • -
-
    -
  • - -

    Returns number

    -

    the unique ID assigned to this AsyncResource instance.

    -
  • -
-
-
- -

bind

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

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

    -
    -
    -

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

    Check to see if the worker should be terminated, because its living too long.

    -
    -
    -

    Returns void

    -
  • -
-
-
- -

Private checkFunctionInput

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

    Check if the fn parameter is passed to the constructor.

    -
    -
    -

    Parameters

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

      The function that should be defined.

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

          Parameters

          -
            -
          • -
            data: Data
            -
          • -
          -

          Returns Response

          -
        • -
        -
      • -
      -
    • -
    -

    Returns void

    -
  • -
-
-
- -

emitDestroy

-
    -
  • emitDestroy(): void
  • -
-
    -
  • - -
    -
    -

    Call AsyncHooks destroy callbacks.

    -
    -
    -

    Returns void

    -
  • -
-
-
- -

Protected getMainWorker

-
    -
  • getMainWorker(): MainWorker
  • -
- -
-
- -

Protected handleError

-
    -
  • handleError(e: string | Error): string
  • -
-
    -
  • - -
    -
    -

    Handle 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

    -

    Message of the error.

    -
  • -
-
-
- -

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

    -
    -
    -

    Type parameters

    -
      -
    • -

      This

      -
    • -
    • -

      Result

      -
    • -
    -

    Parameters

    -
      -
    • -
      fn: (...args: any[]) => Result
      -
      -

      The function to call in the execution context of this - async resource.

      -
      -
        -
      • -
          -
        • (...args: any[]): Result
        • -
        -
          -
        • -

          Parameters

          -
            -
          • -
            Rest ...args: any[]
            -
          • -
          -

          Returns Result

          -
        • -
        -
      • -
      -
    • -
    • -
      Optional thisArg: This
      -
      -

      The receiver to be used for the function call.

      -
      -
    • -
    • -
      Rest ...args: any[]
      -
      -

      Optional arguments to pass to the function.

      -
      -
    • -
    -

    Returns Result

    -
  • -
-
-
- -

Protected Abstract sendToMainWorker

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

    Send a message to the main worker.

    -
    -
    -

    Parameters

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

      The response message.

      -
      -
    • -
    -

    Returns void

    -
  • -
-
-
- -

triggerAsyncId

-
    -
  • triggerAsyncId(): number
  • -
-
    -
  • - -

    Returns number

    -

    the trigger ID for this AsyncResource instance.

    -
  • -
-
-
- -

Static bind

-
    -
  • bind<Func>(fn: Func, type?: string): Func & { asyncResource: AsyncResource }
  • -
-
    -
  • - -
    -
    -

    Binds the given function to the current execution context.

    -
    -
    -

    Type parameters

    -
      -
    • -

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

      -
    • -
    -

    Parameters

    -
      -
    • -
      fn: Func
      -
      -

      The function to bind to the current execution context.

      -
      -
    • -
    • -
      Optional type: string
      -
      -

      An optional name to associate with the underlying AsyncResource.

      -
      -
    • -
    -

    Returns Func & { asyncResource: AsyncResource }

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

Generated using TypeDoc

-
-
- - - \ No newline at end of file +AbstractWorker | poolifier
Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AbstractWorker<MainWorker, Data, Response>

+

Base class containing some shared logic for all poolifier workers.

+

Type parameters

  • MainWorker: Worker | MessagePort

    +

    Type of main worker.

    +
  • Data = unknown

    +

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

    +
  • Response = unknown

    +

    Type of response the worker sends back to the main worker. This can only be serializable data.

    +

Hierarchy

Index

Constructors

constructor

  • new AbstractWorker<MainWorker, Data, Response>(type: string, isMain: boolean, fn: (data: Data) => Response, mainWorker: undefined | null | MainWorker, opts?: WorkerOptions): AbstractWorker<MainWorker, Data, Response>
  • +

    Constructs a new poolifier worker.

    +

    Type parameters

    • MainWorker: Worker | MessagePort

    • Data = unknown

    • Response = unknown

    Parameters

    • type: string
      +

      The type of async event.

      +
    • isMain: boolean
      +

      Whether this is the main worker or not.

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

    • mainWorker: undefined | null | MainWorker
      +

      Reference to main worker.

      +
    • opts: WorkerOptions = ...
      +

      Options for the worker.

      +

    Returns AbstractWorker<MainWorker, 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 | MainWorker

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

Private checkFunctionInput

  • checkFunctionInput(fn: (data: Data) => Response): void
  • +

    Check if the fn parameter is passed to the constructor.

    +

    Parameters

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

      The function that should be defined.

      +
        • (data: Data): Response
        • Parameters

          • data: Data

          Returns Response

    Returns void

Private checkWorkerOptions

emitDestroy

  • +

    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 AbstractWorker<MainWorker, Data, Response>

    A reference to asyncResource.

    +

Protected getMainWorker

  • getMainWorker(): MainWorker

Protected handleError

  • handleError(e: string | Error): string
  • +

    Handle 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

    Message of the error.

    +

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

    • This

    • Result

    Parameters

    • fn: (...args: any[]) => Result
      +

      The function to call in the execution context of this async resource.

      +
        • (...args: any[]): Result
        • Parameters

          • Rest ...args: any[]

          Returns Result

    • Optional thisArg: This
      +

      The receiver to be used for the function call.

      +
    • Rest ...args: any[]
      +

      Optional arguments to pass to the function.

      +

    Returns Result

Protected Abstract sendToMainWorker

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

    Send a message to the main worker.

    +

    Parameters

    • message: MessageValue<Response, unknown>
      +

      The response message.

      +

    Returns void

triggerAsyncId

  • triggerAsyncId(): number
  • Returns number

    The same triggerAsyncId that is passed to the AsyncResource constructor.

    +

Static bind

  • bind<Func, ThisArg>(fn: Func, type?: string, thisArg?: ThisArg): Func & { asyncResource: AsyncResource }
  • +

    Binds the given function to the current execution context.

    +

    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

    • ThisArg

    Parameters

    • fn: Func
      +

      The function to bind to the current execution context.

      +
    • Optional type: string
      +

      An optional name to associate with the underlying AsyncResource.

      +
    • Optional thisArg: ThisArg

    Returns Func & { asyncResource: AsyncResource }

Generated using TypeDoc

\ No newline at end of file