X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=docs%2Fclasses%2Fthreadworker.html;fp=docs%2Fclasses%2Fthreadworker.html;h=08ea47f802c60dc01819515f142c1b0b3c821dc3;hb=aa4307c339b5e1b49c04bcbaee597f48830b1f12;hp=60bd61710c53494e310b1b10ba7d7de550dc68fc;hpb=4f4ae1cb3c33228a023ea599c2648268d15e6c0f;p=poolifier.git diff --git a/docs/classes/threadworker.html b/docs/classes/threadworker.html index 60bd6171..08ea47f8 100644 --- a/docs/classes/threadworker.html +++ b/docs/classes/threadworker.html @@ -8,15 +8,15 @@ but the minimum number of workers will be guaranteed.

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

Hierarchy

Index

Constructors

constructor

Type parameters

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
+

Returns ThreadWorker<Data, Response>

Properties

Protected Optional Readonly aliveInterval

aliveInterval?: Timeout

Handler Id of the aliveInterval worker alive check.

-

Protected lastTaskTimestamp

lastTaskTimestamp: number
+

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 }
  • @@ -26,7 +26,7 @@ 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

Returns Func & { asyncResource: AsyncResource }

Protected checkAlive

  • checkAlive(): void

emitDestroy

  • Call all destroy hooks. This should only ever be called once. An error will @@ -34,21 +34,21 @@ be thrown if it is called more than once. This must be manually 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 getMainWorker

  • getMainWorker(): MessagePort

Protected handleError

  • handleError(e: string | Error): string

Protected handleError

  • handleError(e: string | Error): string

Protected run

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

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

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.

      @@ -66,7 +66,7 @@ then restore the original execution context.

      The receiver to be used for the function call.

    • Rest ...args: any[]

      Optional arguments to pass to the function.

      -

    Returns Result

Protected sendToMainWorker

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

Returns Result

Protected sendToMainWorker

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