X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=docs%2Fclasses%2FThreadWorker.html;h=0fba4af1fa8ea74c1b1541c13f1162d3765302ac;hb=62a7baffdaf232cdaaf94b918c9b8ef43b6bfbb8;hp=1c2345435339a40ce1d0d111e2ef01df67fa5ae0;hpb=069e56f4a71b48e89eeb1b4b2ccf693b75116f07;p=poolifier.git diff --git a/docs/classes/ThreadWorker.html b/docs/classes/ThreadWorker.html index 1c234543..7ff9daf4 100644 --- a/docs/classes/ThreadWorker.html +++ b/docs/classes/ThreadWorker.html @@ -1,805 +1,84 @@ -
Protected
getReturns the main worker.
+Reference to the main worker.
+https://nodejs.org/api/errors.html#class-error If the main worker is not set.
+Protected
handleProtected
handleHandles a kill message sent by the main worker.
+Protected
handleHandles the ready message sent by the main worker.
+The ready message.
+Protected
handleChecks if the worker has a task function with the given name.
+The name of the task function to check.
+Whether the worker has a task function with the given name or not.
+Protected
messageWorker message listener.
+The received message.
+Removes a task function from the worker.
+The name of the task function to remove.
+Whether the task function existed and was removed or not.
+Protected
Readonly
runProtected
Readonly
runRuns the given task function asynchronously.
+Task function that will be executed.
+Input data for the task function.
+Protected
Readonly
runRuns the given task function synchronously.
+Task function that will be executed.
+Input data for the task function.
+Protected
sendProtected
Readonly
sendSends a message to main worker.
+The response message.
+Sets the default task function to use in the worker.
+The name of the task function to use as default task function.
+Whether the default task function was set or not.
+Generated using TypeDoc
A thread worker used by a poolifier
+ThreadPool
.- Preparing search index...
- The search index is not available
poolifier - v3.1.14Class ThreadWorker<Data, Response>
A thread worker used by a poolifier
ThreadPool
.When this worker is inactive for more than the given
maxInactiveTime
, it will send a termination request to its main thread.If you use a
-DynamicThreadPool
the extra workers that were created will be terminated, but the minimum number of workers will be guaranteed.Author
Alessandro Pio Ardizio
- +Author
Alessandro Pio Ardizio
Since
0.0.1
-Type Parameters
---
-
-
--
-
-
Data = unknown
-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 structured-cloneable data.
-Hierarchy
--- AbstractWorker<MessagePort, Data, Response>
-
-- ThreadWorker
-
-Index
Constructors
-Properties
-Type Parameters
Data = unknown
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 structured-cloneable data.
+Hierarchy (view full)
Index
Constructors
Properties
Accessors
-Methods
-Accessors
Methods
Constructors
-constructor
--- new
Thread Worker<Data, Response>(taskFunctions, opts?): ThreadWorker<Data, Response>
--
-
-
-
-
-
-
Constructs a new poolifier thread worker.
-Type Parameters
---
-
--
-
Data = unknown
Response = unknown
Parameters
---
-
-
--
-
-
taskFunctions: TaskFunction<Data, Response> | TaskFunctions<Data, Response>
-Task function(s) processed by the worker when the pool's
-execution
function is invoked.opts: WorkerOptions = {}
-Options for the worker.
-Returns ThreadWorker<Data, Response>
-Properties
- Interval
-Protected
Optional
activeHandler id of the
-activeInterval
worker activity check. Main
-Protected
Readonly
isWhether this is the main worker or not.
- Task Timestamp
-Protected
lastTimestamp of the last task processed by this worker.
-
-Protected
optsOptions for the worker.
-
-Private
portMessage port used to communicate with the main worker.
-
-Protected
statisticsPerformance statistics computation requirements.
- Functions
-Protected
taskTask function(s) processed by the worker when the pool's
-execution
function is invoked.Accessors
-
-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. +
Constructors
constructor
Constructs a new poolifier thread worker.
+Type Parameters
Data = unknown
Response = unknown
Parameters
taskFunctions: TaskSyncFunction<Data, Response> | TaskAsyncFunction<Data, Response> | TaskFunctions<Data, Response>
Task function(s) processed by the worker when the pool's
+execution
function is invoked.opts: WorkerOptions = {}
Options for the worker.
+Returns ThreadWorker<Data, Response>
Properties
Protected
Optional
activeHandler id of the
+activeInterval
worker activity check.Protected
Readonly
isWhether this is the main worker or not.
+Protected
lastTimestamp of the last task processed by this worker.
+Protected
optsOptions for the worker.
+Private
Optional
portMessage port used to communicate with the main worker.
+Protected
statisticsPerformance statistics computation requirements.
+Protected
taskTask function(s) processed by the worker when the pool's
+execution
function is invoked.Accessors
Protected
idWorker id.
+Returns number
Methods
add Task Function
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 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 or an empty 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
--- async
Id(): number
--
-
Returns number
The unique
- -asyncId
assigned to the resource.bind
--- bind<Func>(fn): Func
--
-
-
-
-
-
-
-
Binds the given function to execute to this
-AsyncResource
's scope.Type Parameters
---
-
Func extends ((...args) => any)
Parameters
---
-
-
fn: Func
-The function to bind to the current
-AsyncResource
.Returns Func
-Since
v14.8.0, v12.19.0
-emit Destroy
--- emit
Destroy(): ThreadWorker<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 ThreadWorker<Data, Response>
A reference to
- -asyncResource
. Main Worker
-Protected
get-- get
Main Worker(): MessagePort
--
-
-
Returns the main worker.
-Returns MessagePort
Reference to the main worker.
- - 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
---
-
-
e: string | Error
-The error raised by the worker.
-Returns string
The error message.
- - Kill Message
-Protected
handle-- handle
Kill Message(message): void
--
-
-
-
-
Handles a kill message sent by the main worker.
-Parameters
---
-
-
message: MessageValue<Data, unknown>
-The kill message.
-Returns void
- Ready Message
-Protected
handle-- handle
Ready Message(message): void
--
-
-
-
-
Handles the ready message sent by the main worker.
-Parameters
---
-
-
message: MessageValue<Data, unknown>
-The ready message.
-Returns void
-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 or an empty 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.
- - Listener
-Protected
message-- message
Listener(message): void
--
-
-
-
-
Worker message listener.
-Parameters
---
-
-
message: MessageValue<Data, unknown>
-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 or an empty 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.
- Async
-Protected
run-- run
Async(fn, task): void
--
-
-
-
-
Runs the given task function asynchronously.
-Parameters
---
-
-
--
-
-
fn: TaskAsyncFunction<Data, Response>
-Task function that will be executed.
-task: Task<Data>
-Input data for the task function.
-Returns void
-run In Async Scope
--- 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 -before callbacks, call the function, trigger the AsyncHooks after callbacks, and -then restore the original execution context.
-Type Parameters
---
-
--
-
This
Result
Parameters
---
-
-
-
--
-
-
--
-
-
fn: ((this, ...args) => Result)
-The function to call in the execution context of this async resource.
---
-
-- (this, ...args): Result
--
-
-
-
Parameters
---
-
--
-
this: This
Rest
...args: any[]Returns Result
-Optional
thisArg: ThisThe receiver to be used for the function call.
-
-Rest
...args: any[]Optional arguments to pass to the function.
-Returns Result
-Since
v9.6.0
- Sync
-Protected
run-- run
Sync(fn, task): void
--
-
-
-
-
Runs the given task function synchronously.
-Parameters
---
-
-
--
-
-
fn: TaskSyncFunction<Data, Response>
-Task function that will be executed.
-task: Task<Data>
-Input data for the task function.
-Returns void
- Task Functions List To Main Worker
-Protected
send-- send
Task Functions List To Main Worker(): void
--
-
-
Sends the list of task function names to the main worker.
-Returns void
- To Main Worker
-Protected
send-- send
To Main Worker(message): void
--
-
-
-
-
Sends a message to main worker.
-Parameters
---
-
-
message: MessageValue<Response, unknown>
-The response message.
-Returns void
-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 or an empty 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
--- trigger
Async Id(): number
--
-
Returns number
The same
- -triggerAsyncId
that is passed to theAsyncResource
constructor.
-Static
bind-- bind<Func, ThisArg>(fn, type?, thisArg?): Func
--
-
-
-
-
-
-
-
Binds the given function to the current execution context.
-Type Parameters
---
-
--
-
Func extends ((this, ...args) => any)
ThisArg
Parameters
---
-
-
--
-
-
--
-
fn: Func
-The function to bind to the current execution context.
-
-Optional
type: stringAn optional name to associate with the underlying
-AsyncResource
.Optional
thisArg: ThisArgReturns Func
-Since
v14.8.0, v12.19.0
--
-Settings
Member Visibility
Theme
-
-On This Page
-- constructor
-- active
Interval
-- is
Main
-- last
Task Timestamp
-- opts
-- port
-- statistics
-- task
Functions
-- id
-- add
Task Function
-- async
Id
-- bind
-- emit
Destroy
-- get
Main Worker
-- handle
Error
-- handle
Kill Message
-- handle
Ready Message
-- has
Task Function
-- list
Task Functions
-- message
Listener
-- remove
Task Function
-- run
-- run
Async
-- run
In Async Scope
-- run
Sync
-- send
Task Functions List To Main Worker
-- send
To Main Worker
-- set
Default Task Function
-- trigger
Async Id
-- bind
Generated using TypeDoc
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.
+