X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=docs%2Fclasses%2FAbstractWorker.html;h=e89be619220dfa10a431c0df6c370faef4292047;hb=60af1e8cbf3a50b1d6f3e9a54aea0b9ff92f73f6;hp=2d650398b30c7c574d7479c24dd129d83199e475;hpb=afa30fd0dd5bbc5d305cc30be663966a449efc08;p=poolifier.git diff --git a/docs/classes/AbstractWorker.html b/docs/classes/AbstractWorker.html index 2d650398..e89be619 100644 --- a/docs/classes/AbstractWorker.html +++ b/docs/classes/AbstractWorker.html @@ -1,13 +1,13 @@ -
Type of data this worker receives from pool's execution. This can only be serializable data.
+Type of data this worker receives from pool's execution. This can only be structured-cloneable data.
Response = unknown
-Type of response the worker sends back to the main worker. This can only be serializable data.
+Type of response the worker sends back to the main worker. This can only be structured-cloneable data.
-
+Index
Index
Constructors
-Properties
-Methods
-Constructors
constructor
+constructor
-- new
Abstract Worker<MainWorker, Data, Response>(type, isMain, taskFunctions, mainWorker, opts?): AbstractWorker<MainWorker, Data, Response>
+- new
Abstract Worker<MainWorker, Data, Response>(type, isMain, mainWorker, taskFunctions, opts?): AbstractWorker<MainWorker, Data, Response>
-
@@ -101,7 +116,7 @@
-
-
+
-
-
@@ -120,17 +135,17 @@
Constructs a new poolifier worker.
Type Parameters
MainWorker extends Worker | MessagePort
MainWorker extends MessagePort | Worker
Data = unknown
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: MainWorker
+Reference to main worker.
mainWorker: undefined | null | MainWorker
-Reference to main worker.
+taskFunctions: TaskFunction<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.opts: WorkerOptions = ...
+opts: WorkerOptions = DEFAULT_WORKER_OPTIONS
Options for the worker.
Properties
- Interval
-Protected
Optional
Readonly
aliveHandler id of the
+aliveInterval
worker alive check. Interval
+Protected
Optional
activeHandler id of the
+activeInterval
worker activity check.
+Protected
Abstract
idWorker id.
Protected
Readonly
isProtected
last Worker
-Protected
main Worker
+Private
Readonly
mainReference to main worker.
-Protected
Readonly
opts
+Protected
optsOptions for the worker.
-Protected
statisticsPerformance statistics computation.
+Performance statistics computation requirements.
Functions
-Protected
taskTask function(s) processed by the worker when the pool's
execution
function is invoked.Methods
+add Task Function
++- add
Task Function(name, fn): TaskFunctionOperationResult
+-
+
+
+
+
Adds a task function to the worker. +If a task function with the same name already exists, it is replaced.
+Parameters
++-
+
+
+-
+
+
name: string
+The name of the task function to add.
+fn: TaskFunction<Data, Response>
+The task function to add.
+Returns TaskFunctionOperationResult
Whether the task function was added or not.
+ +async Id
@@ -209,20 +258,20 @@
Private
begin-- begin
Task Performance(message): TaskPerformance
+- begin
Task Performance(name?): TaskPerformance
-
-
-
-
Parameters
message: MessageValue<Data, Worker | MessagePort>
Returns TaskPerformance
Returns TaskPerformance
bind
@@ -249,37 +298,66 @@
Alive
-Protected
check-- check
Alive(): void
+- Defined in node_modules/.pnpm/@types+node@20.8.2/node_modules/@types/node/async_hooks.d.ts:288
Active
+Private
check+- check
Active(): void
-
Checks if the worker should be terminated, because its living too long.
Returns void
Message Worker Id
+Private
check+- check
Message Worker Id(message): void
+-
+
+
+
+
+
Check if the message worker id is set and matches the worker id.
+Parameters
++-
+
+
message: MessageValue<Data, unknown>
+The message to check.
+Returns void
+Throws
https://nodejs.org/api/errors.html#class-error If the message worker id is not set or does not match the worker id.
+ Statistics
+Private
check+- check
Statistics(): void
+-
+
Returns void
Private
checkChecks if the
+taskFunctions
parameter is passed to the constructor.Checks if the
taskFunctions
parameter is passed to the constructor and valid.Parameters
taskFunctions: WorkerFunction<Data, Response> | TaskFunctions<Data, Response>
+taskFunctions: TaskFunction<Data, Response> | TaskFunctions<Data, Response>
The task function(s) parameter that should be checked.
Returns void
+Private
check@@ -292,7 +370,7 @@
opts: WorkerOptions
Returns void
emit Destroy
@@ -308,20 +386,20 @@ never be called.
Private
end-- end
Task Performance(taskPerformance): TaskPerformance
+- end
Task Performance(taskPerformance): TaskPerformance
-
-
-
-
Parameters
taskPerformance: TaskPerformance
Returns TaskPerformance
Returns TaskPerformance
Protected
get@@ -331,48 +409,114 @@ never be called.
Returns MainWorker
Reference to the main worker.
+Throws
https://nodejs.org/api/errors.html#class-error If the main worker is not set.
+ Error
+Protected
handle+- handle
Error(error): string
+-
+
+
+
+
Handles an error and convert it to a string so it can be sent back to the main worker.
+Parameters
++-
+
+
error: string | Error
+The error raised by the worker.
+Returns string
The error message.
+ Task Function
-Private
get-- get
Task Function(name?): WorkerFunction<Data, Response>
+- Defined in src/worker/abstract-worker.ts:485
Kill Message
+Protected
handle+- handle
Kill Message(message): void
-
-
-
-
-
-
-- Defined in src/worker/abstract-worker.ts:371
+
+ Ready Message
+
\ No newline at end of file
Gets the task function in the given scope.
+Handles a kill message sent by the main worker.
Parameters
-Optional
name: stringName of the function that will be returned.
+message: MessageValue<Data, unknown>
+The kill message.
Returns WorkerFunction<Data, Response>
+Returns void
Error
+Protected
handleProtected
Abstract
handle-- handle
Error(e): string
+- handle
Ready Message(message): void
-
-
-
-
-
+
+
+
+
+- Defined in src/worker/abstract-worker.ts:162
+
+
Listener
+
+
+
+
+- Defined in src/worker/abstract-worker.ts:494
Async
-
-
\ No newline at end of file
+
Handles an error and convert it to a string so it can be sent back to the main worker.
+Handles the ready message sent by the main worker.
Parameters
e: string | Error
-The error raised by the worker.
+message: MessageValue<Data, unknown>
+The ready message.
Returns string
Message of the error.
+Returns void
+ Task Function Operation Message
+Protected
handle+- handle
Task Function Operation Message(message): void
+-
+
+
+
Parameters
++-
+
message: MessageValue<Data, unknown>
Returns void
has Task Function
++- has
Task Function(name): TaskFunctionOperationResult
+-
+
+
+
+
Checks if the worker has a task function with the given name.
+Parameters
++-
+
+
name: string
+The name of the task function to check.
+Returns TaskFunctionOperationResult
Whether the worker has a task function with the given name or not.
list Task Function Names
++- list
Task Function Names(): string[]
+-
+
+
Lists the names of the worker's task functions.
+Returns string[]
The names of the worker's task functions.
+ +Protected
message@@ -384,38 +528,77 @@ never be called.-
-
+
+
Parameters
message: MessageValue<Data, MainWorker>
-Message received.
+message: MessageValue<Data, unknown>
+The received message.
+Returns void
+remove Task Function
++- remove
Task Function(name): TaskFunctionOperationResult
+-
+
+
+
+
Removes a task function from the worker.
+Parameters
++-
+
+
name: string
+The name of the task function to remove.
+Returns TaskFunctionOperationResult
Whether the task function existed and was removed or not.
+ +
+Protected
run+- run(task): void
+-
+
+
+
Runs the given task.
+Parameters
++-
+
task: Task<Data>
+The task to execute.
Returns void
Protected
run-- run
Async(fn, message): void
+- run
Async(fn, task): void
-
-
-
-
-
-
+- Defined in src/worker/abstract-worker.ts:555
+- Defined in node_modules/.pnpm/@types+node@20.8.2/node_modules/@types/node/async_hooks.d.ts:299
Sync
+
Runs the given function asynchronously.
+Runs the given task function asynchronously.
Parameters
fn: WorkerAsyncFunction<Data, Response>
-Function that will be executed.
+fn: TaskAsyncFunction<Data, Response>
+Task function that will be executed.
message: MessageValue<Data, Worker | MessagePort>
-Input data for the given function.
+task: Task<Data>
+Input data for the task function.
Returns void
run In Async Scope
@@ -470,50 +653,103 @@ then restore the original execution context.
Protected
run-- run
Sync(fn, message): void
+- run
Sync(fn, task): void
-
-
-
-
-
-
+- Defined in src/worker/abstract-worker.ts:521
+
+
To Main Worker
- send
To Main Worker(message): void
-
-
-
-
- Defined in src/worker/abstract-worker.ts:466
+
+
+
+
+
+
+- Defined in node_modules/.pnpm/@types+node@20.8.2/node_modules/@types/node/async_hooks.d.ts:319
+
+
+ - Defined in node_modules/.pnpm/@types+node@20.8.2/node_modules/@types/node/async_hooks.d.ts:278
+
+
+
+
-
Runs the given function synchronously.
+Runs the given task function synchronously.
Parameters
fn: WorkerSyncFunction<Data, Response>
-Function that will be executed.
+fn: TaskSyncFunction<Data, Response>
+Task function that will be executed.
message: MessageValue<Data, Worker | MessagePort>
-Input data for the given function.
+task: Task<Data>
+Input data for the task function.
Returns void
Task Function Names To Main Worker
+Protected
send+- send
Task Function Names To Main Worker(): void
+-
+
+
Sends task function names to the main worker.
+Returns void
+Protected
Abstract
sendSends a message to the main worker.
+Sends a message to main worker.
Parameters
message: MessageValue<Response, Worker | MessagePort>
+message: MessageValue<Response, Data>
The response message.
Returns void
+set Default Task Function
++- set
Default Task Function(name): TaskFunctionOperationResult
+-
+
+
+
+
Sets the default task function to use in the worker.
+Parameters
++-
+
+
name: string
+The name of the task function to use as default task function.
+Returns TaskFunctionOperationResult
Whether the default task function was set or not.
+ + Check Active
+Private
start+- start
Check Active(): void
+-
+
+
Starts the worker check active interval.
+Returns void
+ Check Active
+Private
stop+- stop
Check Active(): void
+-
+
+
Stops the worker check active interval.
+Returns void
+trigger Async Id
@@ -524,7 +760,15 @@ then restore the original execution context.
Last Task Timestamp
+Private
update+- update
Last Task Timestamp(): void
+-
+
Returns void
Static
bind@@ -560,20 +804,20 @@ then restore the original execution context.
-
+Settings
Settings
Member Visibility
Theme
@@ -581,81 +825,71 @@ then restore the original execution context.
- constructor
-- alive
Interval
+- active
Interval
+- id
- is
Main
- last
Task Timestamp
-- main
Worker
+- main
Worker
- opts
- statistics
- task
Functions
+- add
Task Function
- async
Id
- begin
Task Performance
- bind
-- check
Alive
+- check
Active
+- check
Message Worker Id
+- check
Statistics
- check
Task Functions
- check
Worker Options
- emit
Destroy
- end
Task Performance
- get
Main Worker
-- get
Task Function
- handle
Error
+- handle
Kill Message
+- handle
Ready Message
+- handle
Task Function Operation Message
+- has
Task Function
+- list
Task Function Names
- message
Listener
+- remove
Task Function
+- run
- run
Async
- run
In Async Scope
- run
Sync
+- send
Task Function Names To Main Worker
- send
To Main Worker
+- set
Default Task Function
+- start
Check Active
+- stop
Check Active
- trigger
Async Id
+- update
Last Task Timestamp
- bind
Generated using TypeDoc
Generated using TypeDoc