X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=inline;f=docs%2Fclasses%2FAbstractWorker.html;h=2040352d263a2b55892af561c6ac1c25cc02b5b3;hb=8d98e603c79d8d00b2b6a33e5f732701a7466234;hp=93d756358781097a99a0d376fdfb6f16318311bd;hpb=b142df6d1278e9d0b6c4c7226bf3dae36c486410;p=poolifier.git diff --git a/docs/classes/AbstractWorker.html b/docs/classes/AbstractWorker.html index 93d75635..2040352d 100644 --- a/docs/classes/AbstractWorker.html +++ b/docs/classes/AbstractWorker.html @@ -1,47 +1,49 @@ -
Abstract
Base class containing some shared logic for all poolifier workers.
+Base class that implements some shared logic for all poolifier workers.
Type Parameters
-+-
-
-
-
-
-
MainWorker extends Worker | MessagePort
+MainWorker extends Worker | MessagePort
Type of main worker.
Data = unknown
+Data = unknown
Type of data this worker receives from pool's execution. This can only be serializable data.
Response = unknown
+Response = unknown
Type of response the worker sends back to the main worker. This can only be serializable data.
Hierarchy
-- AsyncResource
+
- AsyncResource
- AbstractWorker
-- ClusterWorker
-- ThreadWorker
@@ -49,350 +51,306 @@
constructor
+constructor
alive Interval?
-last Task Timestamp
-main Worker
-opts
+alive Interval?
+is Main
+last Task Timestamp
+main Worker
+opts
+task Functions
async Id
-bind
-check Alive
-check Function Input
-check Worker Options
-emit Destroy
-get Main Worker
-handle Error
-message Listener
-run
-run Async
-run In Async Scope
-send To Main Worker
-trigger Async Id
-bind
+async Id
+bind
+check Alive
+check Task Functions
+check Worker Options
+emit Destroy
+get Main Worker
+get Task Function
+handle Error
+message Listener
+run Async
+run In Async Scope
+run Sync
+send To Main Worker
+trigger Async Id
+bind
+
+
-
-
-
-
-
-
-
+
-
-
-
-
-
+Defined in src/worker/abstract-worker.ts:55
+
alive Interval?: Timeout
-alive Interval?: Timeout
+
-
+Defined in src/worker/abstract-worker.ts:45
+
+is Main: boolean
+
+
+
last Task Timestamp: number
+last Task Timestamp: number
-
+Defined in src/worker/abstract-worker.ts:41
+
main Worker: undefined | null | MainWorker
+main Worker: undefined | null | MainWorker
+
-
-opts: WorkerOptions
+Defined in src/worker/abstract-worker.ts:61
+
+opts: WorkerOptions = ...
+Defined in src/worker/abstract-worker.ts:62
+
+task Functions: Map<string, WorkerFunction<Data, Response>>
+
+
+
-
+Defined in node_modules/.pnpm/@types+node@20.2.5/node_modules/@types/node/async_hooks.d.ts:306
+
-
-
-
+
-
+Defined in node_modules/.pnpm/@types+node@20.2.5/node_modules/@types/node/async_hooks.d.ts:283
+
-
+Defined in src/worker/abstract-worker.ts:89
+
-
+Defined in node_modules/.pnpm/@types+node@20.2.5/node_modules/@types/node/async_hooks.d.ts:302
+
-
-
+
+
-
+constructor
+alive Interval
+is Main
+last Task Timestamp
+main Worker
+opts
+task Functions
+async Id
+bind
+check Alive
+check Task Functions
+check Worker Options
+emit Destroy
+get Main Worker
+get Task Function
+handle Error
+message Listener
+run Async
+run In Async Scope
+run Sync
+send To Main Worker
+trigger Async Id
+bind
+
+
Constructors
-Properties
-Methods
-Constructors
-constructor
--- new
Abstract Worker<MainWorker, Data, Response>(type: string, isMain: boolean, fn: ((data: Data) => Response), mainWorker: undefined | null | MainWorker, opts?: WorkerOptions): AbstractWorker<MainWorker, Data, Response>
+
+- new
Abstract Worker<MainWorker, Data, Response>(type, isMain, taskFunctions, mainWorker, opts?): AbstractWorker<MainWorker, Data, Response>
-
-
+
-
-
+-
-
Constructs a new poolifier worker.
Type Parameters
-+-
-
+
MainWorker extends Worker | MessagePort
MainWorker extends Worker | MessagePort
Data = unknown
Data = unknown
Response = unknown
Response = unknown
Parameters
type: string
+type: string
The type of async event.
isMain: boolean
+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
taskFunctions: WorkerFunction<Data, Response> | TaskFunctions<Data, Response>
+Task function(s) processed by the worker when the pool's
+execution
function is invoked. The first function is the default function.mainWorker: undefined | null | MainWorker
+mainWorker: undefined | null | MainWorker
Reference to main worker.
opts: WorkerOptions = ...
+opts: WorkerOptions = ...
Options for the worker.
Returns AbstractWorker<MainWorker, Data, Response>
Properties
- Interval
-Protected
Optional
Readonly
aliveHandler Id of the
+aliveInterval
worker alive check.Handler id of the
aliveInterval
worker alive check.-- Defined in src/worker/abstract-worker.ts:31
Main
+Protected
Readonly
isWhether this is the main worker or not.
++- Defined in src/worker/abstract-worker.ts:57
Task Timestamp
-Protected
lastTimestamp of the last task processed by this worker.
-- Defined in src/worker/abstract-worker.ts:27
Worker
-Protected
mainReference to main worker.
+-- Defined in src/worker/abstract-worker.ts:49
-Readonly
opts
+Protected
Readonly
optsOptions for the worker.
-- Defined in src/worker/abstract-worker.ts:35
Functions
+Protected
taskTask function(s) processed by the worker when the pool's
+execution
function is invoked.+- Defined in src/worker/abstract-worker.ts:37
Methods
-async Id
--- async
Id(): number
+
+- async
Id(): number
-
-
-
-
+
+
Returns
The unique
-asyncId
assigned to the resource.Returns number
Returns number
The unique
+asyncId
assigned to the resource.Inherited from AsyncResource.asyncId
-- Defined in node_modules/@types/node/ts4.8/async_hooks.d.ts:315
bind
--- bind<Func>(fn: Func): Func & { asyncResource: AsyncResource }
+
+- bind<Func>(fn): Func
-
-
+
+
Binds the given function to execute to this
-AsyncResource
's scope.The returned function will have an
asyncResource
property referencing -theAsyncResource
to which the function is bound.Since
v14.8.0, v12.19.0
Type Parameters
-+-
-
Func extends ((...args: any[]) => any)
Func extends ((...args) => any)
Parameters
fn: Func
+fn: Func
The function to bind to the current
AsyncResource
.Returns Func & { asyncResource: AsyncResource }
Returns Func
Inherited from AsyncResource.bind
-- Defined in node_modules/@types/node/ts4.8/async_hooks.d.ts:288
Alive
-Protected
check-- check
Alive(): void
+
+- check
Alive(): void
-
-
-
-
+
+
-
+- Defined in src/worker/abstract-worker.ts:101
+
Check to see if the worker should be terminated, because its living too long.
+Checks if the worker should be terminated, because its living too long.
Returns void
-- Defined in src/worker/abstract-worker.ts:144
Function Input
-Private
check-- check
Function Input(fn: ((data: Data) => Response)): void
+- Defined in src/worker/abstract-worker.ts:182
Task Functions
+Private
check+- check
Task Functions(taskFunctions): void
-
-
-
-
-
+
Check if the
+fn
parameter is passed to the constructor.Checks if the
taskFunctions
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
taskFunctions: WorkerFunction<Data, Response> | TaskFunctions<Data, Response>
+The task function(s) parameter that should be checked.
+Returns void
-- Defined in src/worker/abstract-worker.ts:118
Worker Options
-Private
check-- check
Worker Options(opts: WorkerOptions): void
+
+- check
Worker Options(opts): void
-
-
-
+
Parameters
opts: WorkerOptions
opts: WorkerOptions
Returns void
-- Defined in src/worker/abstract-worker.ts:103
emit Destroy
--- emit
Destroy(): AbstractWorker<MainWorker, Data, Response>
+
+- emit
Destroy(): AbstractWorker<MainWorker, Data, Response>
-
-
+
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 thedestroy
hooks will never be called.Returns
A reference to
asyncResource
.Returns AbstractWorker<MainWorker, Data, Response>
Returns AbstractWorker<MainWorker, Data, Response>
A reference to
+asyncResource
.Inherited from AsyncResource.emitDestroy
-- Defined in node_modules/@types/node/ts4.8/async_hooks.d.ts:311
Main Worker
-Protected
get-- get
Main Worker(): MainWorker
+
+- get
Main Worker(): MainWorker
-
-
+
Returns the main worker.
- -Returns
Reference to the main worker.
Returns MainWorker
Returns MainWorker
Reference to the main worker.
+-- Defined in src/worker/abstract-worker.ts:127
Error
-Protected
handle-- handle
Error(e: string | Error): string
+- Defined in src/worker/abstract-worker.ts:165
Task Function
+Private
get+- get
Task Function(name?): WorkerFunction<Data, Response>
-
-
-
-
-
+
-
-
+
-
-
+
+
+
-
Handle an error and convert it to a string so it can be sent back to the main worker.
- -Returns
Message of the error.
+Gets the task function in the given scope.
Parameters
e: string | Error
-The error raised by the worker.
+
+Optional
name: stringName of the function that will be returned.
Returns string
Returns WorkerFunction<Data, Response>
-- Defined in src/worker/abstract-worker.ts:159
Listener
-Protected
message-- message
Listener(value: MessageValue<Data, MainWorker>, fn: ((data: Data) => Response)): void
--
-
-
-
+
Parameters
---
-
--
-
+
value: MessageValue<Data, MainWorker>
fn: ((data: Data) => Response)
---
-
+-- (data: Data): Response
+- Defined in src/worker/abstract-worker.ts:276
Error
+Protected
handle+- handle
Error(e): string
-
+
-
-
-
Handles an error and convert it to a string so it can be sent back to the main worker.
+Parameters
data: Data
Returns Response
Returns void
e: string | Error
+The error raised by the worker.
+Returns string
Message of the error.
+-- Defined in src/worker/abstract-worker.ts:81
-Protected
run-- run(fn: ((data?: Data) => Response), value: MessageValue<Data, unknown>): void
+- Defined in src/worker/abstract-worker.ts:197
Listener
+Protected
message+- message
Listener(message): void
-
-
-
-
-
--
-
-
+- Defined in src/worker/abstract-worker.ts:141
+
-
+- Defined in src/worker/abstract-worker.ts:240
+
+
-
-
-
-
+
+-
-
-
-
-
+
-
+- Defined in node_modules/.pnpm/@types+node@20.2.5/node_modules/@types/node/async_hooks.d.ts:294
+
+
+
-
+- Defined in node_modules/.pnpm/@types+node@20.2.5/node_modules/@types/node/async_hooks.d.ts:277
+
+
-
-
Run the given function synchronously.
+Worker message listener.
Parameters
fn: ((data?: Data) => Response)
-Function that will be executed.
---
-
-- (data?: Data): Response
--
-
-
-
Parameters
---
-
Optional
data: DataReturns Response
value: MessageValue<Data, unknown>
-Input data for the given function.
+message: MessageValue<Data, MainWorker>
+Message received.
Returns void
-- Defined in src/worker/abstract-worker.ts:169
Async
-Protected
run-- run
Async(fn: ((data?: Data) => Promise<Response>), value: MessageValue<Data, unknown>): void
+
+- run
Async(fn, message): void
-
-
-
-
-
+
-
-
Run the given function asynchronously.
+Runs the given function asynchronously.
Parameters
fn: ((data?: Data) => Promise<Response>)
+fn: WorkerAsyncFunction<Data, Response>
Function that will be executed.
---
-
-- (data?: Data): Promise<Response>
--
-
-
-
Parameters
---
-
Optional
data: DataReturns Promise<Response>
value: MessageValue<Data, unknown>
+message: MessageValue<Data, Worker | MessagePort>
Input data for the given function.
Returns void
-- Defined in src/worker/abstract-worker.ts:190
run In Async Scope
--- run
In Async Scope<This, Result>(fn: ((this: This, ...args: any[]) => Result), thisArg?: This, ...args: any[]): Result
+
+- run
In Async Scope<This, Result>(fn, thisArg?, ...args): 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 @@ -401,113 +359,132 @@ then restore the original execution context.
Since
v9.6.0
Type Parameters
-+-
-
+
This
This
Result
Result
Parameters
fn: ((this: This, ...args: any[]) => Result)
+fn: ((this, ...args) => Result)
The function to call in the execution context of this async resource.
-- (this: This, ...args: any[]): Result
+
+- (this, ...args): Result
-
-
-
+-
-
-
Parameters
this: This
this: This
Rest
...args: any[]Returns Result
Rest
...args: any[]Returns Result
+Optional
thisArg: ThisOptional
thisArg: ThisThe receiver to be used for the function call.
+Rest
...args: any[]Rest
...args: any[]Optional arguments to pass to the function.
Returns Result
Returns Result
Inherited from AsyncResource.runInAsyncScope
-- Defined in node_modules/@types/node/ts4.8/async_hooks.d.ts:303
Sync
+Protected
run+- run
Sync(fn, message): void
+-
+
+
+
+
+
Runs the given function synchronously.
+Parameters
++-
+
+-
+
fn: WorkerSyncFunction<Data, Response>
+Function that will be executed.
+message: MessageValue<Data, Worker | MessagePort>
+Input data for the given function.
+Returns void
+- Defined in src/worker/abstract-worker.ts:207
To Main Worker
-Protected
Abstract
send-- send
To Main Worker(message: MessageValue<Response, unknown>): void
+
+- send
To Main Worker(message): void
-
-
-
-
-
+- Defined in src/worker/abstract-worker.ts:177
+
-
+- Defined in node_modules/.pnpm/@types+node@20.2.5/node_modules/@types/node/async_hooks.d.ts:311
+
+
-
-
-
-
-
-
-
+
+
Send a message to the main worker.
+Sends a message to the main worker.
Parameters
message: MessageValue<Response, unknown>
+message: MessageValue<Response, Worker | MessagePort>
The response message.
Returns void
-- Defined in src/worker/abstract-worker.ts:139
trigger Async Id
--- trigger
Async Id(): number
+
+- trigger
Async Id(): number
-
-
-
-
+
+
Returns
The same
-triggerAsyncId
that is passed to theAsyncResource
constructor.Returns number
Returns number
The same
+triggerAsyncId
that is passed to theAsyncResource
constructor.Inherited from AsyncResource.triggerAsyncId
-- Defined in node_modules/@types/node/ts4.8/async_hooks.d.ts:320
-Static
bind-- bind<Func, ThisArg>(fn: Func, type?: string, thisArg?: ThisArg): Func & { asyncResource: AsyncResource }
+
+- bind<Func, ThisArg>(fn, type?, thisArg?): Func
-
-
+
-
-
Binds the given function to the current execution context.
-The returned function will have an
asyncResource
property referencing -theAsyncResource
to which the function is bound.Since
v14.8.0, v12.19.0
Type Parameters
-+-
-
+
Func extends ((this: ThisArg, ...args: any[]) => any)
Func extends ((this, ...args) => any)
ThisArg
ThisArg
Parameters
fn: Func
+fn: Func
The function to bind to the current execution context.
+Optional
type: stringOptional
type: stringAn optional name to associate with the underlying
AsyncResource
.Optional
thisArg: ThisArgReturns Func & { asyncResource: AsyncResource }
Optional
thisArg: ThisArgReturns Func
Inherited from AsyncResource.bind
-- Defined in node_modules/@types/node/ts4.8/async_hooks.d.ts:273
-
+Settings
Settings
Member Visibility
Theme
+
On This Page
-- poolifier
-
Generated using TypeDoc