X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=docs%2Fclasses%2FThreadWorker.html;h=ebc27124f04aec64ecbb500f7cea443aa54d979e;hb=222387cba569774821d225147ac6f35f4f1bc696;hp=675fd4f114e860f81206eefce07dc878c0ef8b50;hpb=f45a3823ad04902b4c446c7c7de55ca183041953;p=poolifier.git diff --git a/docs/classes/ThreadWorker.html b/docs/classes/ThreadWorker.html index 675fd4f1..ebc27124 100644 --- a/docs/classes/ThreadWorker.html +++ b/docs/classes/ThreadWorker.html @@ -1,4 +1,4 @@ -
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 thread. This can only be serializable data.
+Type of response the worker sends back to the main thread. This can only be structured-cloneable data.
@@ -59,7 +59,7 @@ but the minimum number of workers will be guaranteed.
Properties
-Accessors
+Methods
-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
Readonly
isProtected
last Worker
-Protected
main Worker
+Protected
Readonly
mainReference to main worker.
Protected
Readonly
opts
-Protected
statisticsPerformance statistics computation.
+Performance statistics computation requirements.
Protected
taskAccessors
+
+Protected
id+- get id(): number
+-
+
+
Worker id.
+Returns number
+Methods
+add Task Function
++- add
Task Function(name, fn): boolean
+-
+
+
+
+
+
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: WorkerFunction<Data, Response>
+The task function to add.
+Returns boolean
Whether the task function was added or not.
+ +Throws
https://nodejs.org/api/errors.html#class-typeerror If the
+ +name
parameter is not a string.Throws
https://nodejs.org/api/errors.html#class-error If the
+ +name
parameter is the default task function reserved name.Throws
https://nodejs.org/api/errors.html#class-typeerror If the
+fn
parameter is not a function.async Id
@@ -194,7 +251,7 @@ but the minimum number of workers will be guaranteed.
bind
@@ -221,19 +278,7 @@ but the minimum number of workers will be guaranteed.
Alive
-Protected
check-- check
Alive(): void
--
-
-
Checks if the worker should be terminated, because its living too long.
-Returns void
-emit Destroy
@@ -249,7 +294,7 @@ never be called.
Protected
get@@ -262,10 +307,10 @@ never be called.
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.
@@ -278,12 +323,48 @@ never be called.The error raised by the worker.
Returns string
Message of the error.
+Returns string
The error message.
has Task Function
++- has
Task Function(name): boolean
+-
+
+
+
+
+
Checks if the worker has a task function with the given name.
+Parameters
++-
+
+
name: string
+The name of the task function to check.
+Returns boolean
Whether the worker has a task function with the given name or not.
+ +Throws
https://nodejs.org/api/errors.html#class-typeerror If the
+name
parameter is not a string.list Task Functions
++- list
Task Functions(): string[]
+-
+
+
Lists the names of the worker's task functions.
+Returns string[]
The names of the worker's task functions.
+ +Protected
message@@ -295,40 +376,89 @@ never be called.-
-
Parameters
message: MessageValue<Data, MessagePort>
-Message received.
+message: MessageValue<Data, Data>
+The received message.
Returns void
remove Task Function
++- remove
Task Function(name): boolean
+-
+
+
+
+
+
Removes a task function from the worker.
+Parameters
++-
+
+
name: string
+The name of the task function to remove.
+Returns boolean
Whether the task function existed and was removed or not.
+ +Throws
https://nodejs.org/api/errors.html#class-typeerror If the
+ +name
parameter is not a string.Throws
https://nodejs.org/api/errors.html#class-error If the
+ +name
parameter is the default task function reserved name.Throws
https://nodejs.org/api/errors.html#class-error If the
+name
parameter is the task function used as default task function.
+Protected
run+- run(task): void
+-
+
+
+
+
+
Runs the given task.
+Parameters
++-
+
+
task: Task<Data>
+The task to execute.
+Returns void
+Throws
https://nodejs.org/api/errors.html#class-error If the task function is not found.
+Protected
run-- run
Async(fn, message): void
+- run
Async(fn, task): void
-
-
-
-
-
+- Defined in src/worker/abstract-worker.ts:441
+- Defined in node_modules/.pnpm/@types+node@20.4.2/node_modules/@types/node/async_hooks.d.ts:294
Sync
@@ -496,28 +665,35 @@ then restore the original execution context.
- constructor
-- alive
Interval
+- active
Interval
- is
Main
- last
Task Timestamp
- main
Worker
- opts
- statistics
- task
Functions
+- id
+- add
Task Function
- async
Id
- bind
-- check
Alive
- emit
Destroy
- get
Main Worker
-- handle
Error
+- handle
Error
+- has
Task Function
+- list
Task Functions
- message
Listener
+- remove
Task Function
+- run
- run
Async
- run
In Async Scope
- run
Sync
+- send
Ready Response
- send
To Main Worker
+- set
Default Task Function
- trigger
Async Id
- bind
-
+- Worker
Types
+- available
Parallelism
Runs the given function asynchronously.
+Runs the given task function asynchronously.
Parameters
fn: WorkerAsyncFunction<Data, Response>
-Function that will be executed.
+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
@@ -383,32 +513,44 @@ 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:403
+
+
To Main Worker
@@ -428,7 +570,34 @@ then restore the original execution context.
+- Defined in src/worker/thread-worker.ts:56
+
+
+- Defined in node_modules/.pnpm/@types+node@20.4.2/node_modules/@types/node/async_hooks.d.ts:311
+ - Defined in node_modules/.pnpm/@types+node@20.4.2/node_modules/@types/node/async_hooks.d.ts:277
Runs the given function synchronously.
+Runs the given task function synchronously.
Parameters
fn: WorkerSyncFunction<Data, Response>
-Function that will be executed.
+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
Ready Response
+Protected
send+- send
Ready Response(): void
+-
+
+
Sends the ready response to the main worker.
+Returns void
+Protected
send@@ -420,7 +562,7 @@ then restore the original execution context.-
-
Parameters
message: MessageValue<Response, Worker | MessagePort>
+message: MessageValue<Response, unknown>
The response message.
set Default Task Function
++- set
Default Task Function(name): boolean
+-
+
+
+
+
+
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 boolean
Whether the default task function was set or not.
+ +Throws
https://nodejs.org/api/errors.html#class-typeerror If the
+ +name
parameter is not a string.Throws
https://nodejs.org/api/errors.html#class-error If the
+ +name
parameter is the default task function reserved name.Throws
https://nodejs.org/api/errors.html#class-error If the
+name
parameter is a non-existing task function.trigger Async Id
@@ -439,7 +608,7 @@ then restore the original execution context.
Static
bind@@ -475,7 +644,7 @@ then restore the original execution context.
Generated using TypeDoc