X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=docs%2Fclasses%2FAbstractWorker.html;h=df85f6680ee4b5899780ee0f36af115abac21d0c;hb=fbc22127e53d3ec0ecbd38ecea25fb92ebef50e7;hp=825204bbd3d233ed273b1f47085036680317246b;hpb=c0b0686de0f8c5483b20b94fac97d2b8175c0556;p=poolifier.git diff --git a/docs/classes/AbstractWorker.html b/docs/classes/AbstractWorker.html index 825204bb..df85f668 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,39 +51,40 @@
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
+
-
+Defined in src/worker/abstract-worker.ts:36
+
+is Main: boolean
+
+
+
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 src/worker/abstract-worker.ts:89
+
-
+Defined in src/worker/abstract-worker.ts:181
+
-
+Defined in src/worker/abstract-worker.ts:208
+
-
+Defined in node_modules/.pnpm/@types+node@18.15.11/node_modules/@types/node/async_hooks.d.ts:303
+
-
+constructor
+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
+
+
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>
-
@@ -89,83 +92,81 @@
-
-
+
-
-
+-
-
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>
Returns AbstractWorker<MainWorker, Data, Response>
Overrides AsyncResource.constructor
-- Defined in src/worker/abstract-worker.ts:45
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:48
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
-
-
+- Defined in node_modules/.pnpm/@types+node@18.15.11/node_modules/@types/node/async_hooks.d.ts:315
+
-
+- Defined in src/worker/abstract-worker.ts:110
+
-
+- Defined in node_modules/.pnpm/@types+node@18.15.11/node_modules/@types/node/async_hooks.d.ts:311
+
-
+- Defined in src/worker/abstract-worker.ts:139
+
-
+- Defined in src/worker/abstract-worker.ts:171
+
Returns
The unique
@@ -173,11 +174,11 @@asyncId
assigned to the resource.Returns number
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 & {
-
-
-
+
-
-
-
+
-
+- Defined in node_modules/.pnpm/@types+node@18.15.11/node_modules/@types/node/async_hooks.d.ts:288
+
-
+- Defined in src/worker/abstract-worker.ts:122
+
    asyncResource: AsyncResource;
}
Binds the given function to execute to this
AsyncResource
's scope.The returned function will have an
asyncResource
property referencing @@ -189,73 +190,62 @@ theAsyncResource
to which the function is bound.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 @@ -264,28 +254,28 @@ never be called.Returns
A reference to
asyncResource
.Returns AbstractWorker<MainWorker, Data, Response>
Returns AbstractWorker<MainWorker, Data, Response>
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
-- Defined in src/worker/abstract-worker.ts:127
Error
-Protected
handle-- handle
Error(e: string | Error): string
+
+- handle
Error(e): string
-
-
@@ -293,106 +283,79 @@ never be called.
-
-
Handle an error and convert it to a string so it can be sent back to the main worker.
+Handles an error and convert it to a string so it can be sent back to the main worker.
Returns
Message of the error.
Parameters
e: string | Error
+e: string | Error
The error raised by the worker.
Returns string
-- 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 @@ -405,62 +368,62 @@ then restore the original execution context.
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
+
+
-
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
-
-
+- Defined in node_modules/.pnpm/@types+node@18.15.11/node_modules/@types/node/async_hooks.d.ts:320
+
-
+- Defined in node_modules/.pnpm/@types+node@18.15.11/node_modules/@types/node/async_hooks.d.ts:273
+
+
-
-
Returns
The same
@@ -468,11 +431,11 @@ then restore the original execution context.triggerAsyncId
that is passed to theAsyncResource
constructor.Returns number
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 @@ -484,30 +447,31 @@ theAsyncResource
to which the function is bound.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
-