X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=inline;f=docs%2Fclasses%2FAbstractWorker.html;h=460aac9df0eb0d25f61fdfaa12a766b43df5de46;hb=3dd69d8ee8aa2132fccb106720a9f5ae67b92cc8;hp=825204bbd3d233ed273b1f47085036680317246b;hpb=248bc34b348a7d8d2b90eecff49d60a3b465da9e;p=poolifier.git diff --git a/docs/classes/AbstractWorker.html b/docs/classes/AbstractWorker.html index 825204bb..460aac9d 100644 --- a/docs/classes/AbstractWorker.html +++ b/docs/classes/AbstractWorker.html @@ -1,47 +1,49 @@ -
Abstract
Generated using TypeDoc
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,135 +51,133 @@
constructor
+constructor
alive Interval?
-last Task Timestamp
-main Worker
-opts
+alive Interval?
+is Main
+last Task Timestamp
+main Worker
+opts
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 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
+
+
-
-
-
-
-
-
-
+
-
-
-
+Defined in src/worker/abstract-worker.ts:46
+
alive Interval?: Timeout
-alive Interval?: Timeout
+
+
+
+is Main: boolean
+
-
+Defined in src/worker/abstract-worker.ts:48
+
last Task Timestamp: number
+last Task Timestamp: number
-
+Defined in src/worker/abstract-worker.ts:32
+
main Worker: undefined | null | MainWorker
+main Worker: undefined | null | MainWorker
+
-
-opts: WorkerOptions
+Defined in src/worker/abstract-worker.ts:50
+
+opts: WorkerOptions = ...
+Defined in src/worker/abstract-worker.ts:51
+
-
+Defined in node_modules/.pnpm/@types+node@18.16.3/node_modules/@types/node/async_hooks.d.ts:315
+
-
-
-
+
-
+Defined in node_modules/.pnpm/@types+node@18.16.3/node_modules/@types/node/async_hooks.d.ts:288
+
-
+Defined in src/worker/abstract-worker.ts:95
+
-
+Defined in src/worker/abstract-worker.ts:83
+
-
+Defined in node_modules/.pnpm/@types+node@18.16.3/node_modules/@types/node/async_hooks.d.ts:311
+
-
+Defined in src/worker/abstract-worker.ts:139
+
-
+Defined in src/worker/abstract-worker.ts:113
+
-
+Defined in src/worker/abstract-worker.ts:181
+
-
+Defined in src/worker/abstract-worker.ts:208
+
+
-
-
-
-
+
+
-
-
-
+
-
+Defined in node_modules/.pnpm/@types+node@18.16.3/node_modules/@types/node/async_hooks.d.ts:303
+
-
+Defined in node_modules/.pnpm/@types+node@18.16.3/node_modules/@types/node/async_hooks.d.ts:273
+
+
-
-
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, fn, 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)
+fn: WorkerFunction<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
+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:36
Main
+Protected
Readonly
isWhether this is the main worker or not.
-- Defined in src/worker/abstract-worker.ts:31
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
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 & {
-
-
+
+
    asyncResource: AsyncResource;
}
Binds the given function to execute to this
AsyncResource
's scope.The returned function will have an
asyncResource
property referencing @@ -185,214 +185,173 @@ 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 & {
    asyncResource: AsyncResource;
}
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:156
+
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
+
+- check
Function Input(fn): void
-
-
-
-
-
+
Check if the
+fn
parameter is passed to the constructor.Checks if the
fn
parameter is passed to the constructor.Parameters
fn: ((data: Data) => Response)
+fn: WorkerFunction<Data, Response>
The function that should be defined.
---
-
-- (data: Data): Response
--
-
-
-
Parameters
---
-
data: Data
Returns Response
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
+
+- handle
Error(e): string
-
-
-
-
-
+
-
+- Defined in src/worker/abstract-worker.ts:171
+
Handle an error and convert it to a string so it can be sent back to the main worker.
- -Returns
Message of the error.
+Handles an error and convert it to a string so it can be sent back to the main worker.
Parameters
e: string | Error
+e: string | Error
The error raised by the worker.
Returns string
Returns string
Message of the error.
+-- Defined in src/worker/abstract-worker.ts:159
Listener
-Protected
message-- message
Listener(value: MessageValue<Data, MainWorker>, fn: ((data: Data) => Response)): void
+
+- message
Listener(message, fn): void
-
+
-
-
--
-
+
Worker message listener.
+Parameters
value: MessageValue<Data, MainWorker>
fn: ((data: Data) => Response)
---
-
-- (data: Data): Response
--
-
-
-
Parameters
-+
-
-
message: MessageValue<Data, MainWorker>
+Message received.
+data: Data
Returns Response
fn: WorkerFunction<Data, Response>
+Function processed by the worker when the pool's
+execution
function is invoked.Returns void
-- Defined in src/worker/abstract-worker.ts:81
-Protected
run-- run(fn: ((data?: Data) => Response), value: MessageValue<Data, unknown>): void
+
+- run(fn, message): void
-
-
-
-
-
+
-
-
Run the given function synchronously.
+Runs the given function synchronously.
Parameters
fn: ((data?: Data) => Response)
+fn: WorkerSyncFunction<Data, Response>
Function that will be executed.
---
-
-- (data?: Data): Response
--
-
-
-
Parameters
---
-
Optional
data: DataReturns Response
value: MessageValue<Data, unknown>
+message: MessageValue<Data, unknown>
Input data for the given function.
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, unknown>
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,78 +360,77 @@ 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
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:151
+
-
+- Defined in node_modules/.pnpm/@types+node@18.16.3/node_modules/@types/node/async_hooks.d.ts:320
+
+
-
-
-
-
-
-
-
+
+
Send a message to the main worker.
+Sends a message to the main worker.
Parameters
message: MessageValue<Response, unknown>
+message: MessageValue<Response, unknown>
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 & {
-
-
+
-
-
    asyncResource: AsyncResource;
}
Binds the given function to the current execution context.
The returned function will have an
asyncResource
property referencing @@ -480,34 +438,35 @@ 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 & {
    asyncResource: AsyncResource;
}
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
-