X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=docs%2Fclasses%2FThreadWorker.html;h=767e8744739ad4a19754d3e6502cd038d5470f2f;hb=be55f2ca8b4792c645c4aaee38f0e3471a1efcb2;hp=850e2be0ef2559cc3d4f467452d32cc5095233f5;hpb=18ba88e2f8612c6137bf564388ce8f905ae6d4ee;p=poolifier.git diff --git a/docs/classes/ThreadWorker.html b/docs/classes/ThreadWorker.html index 850e2be0..767e8744 100644 --- a/docs/classes/ThreadWorker.html +++ b/docs/classes/ThreadWorker.html @@ -1,525 +1,112 @@ -
Protected
runRuns the given task function synchronously.
+Task function that will be executed.
+Input data for the task function.
+Protected
sendProtected
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.
+Static
bindBinds the given function to the current execution context.
+The function to bind to the current execution context.
+Optional
type: stringAn optional name to associate with the underlying AsyncResource
.
Optional
thisArg: ThisArgv14.8.0, v12.19.0
+Generated using TypeDoc
A thread worker used by a poolifier
+ThreadPool
.- Preparing search index...
- The search index is not available
poolifier - v3.0.5Class 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
- -Since
0.0.1
-Type Parameters
---
-
--
-
Data = unknown
-Type of data this worker receives from pool's execution. This can only be serializable data.
-Response = unknown
-Type of response the worker sends back to the main thread. This can only be serializable data.
-Hierarchy
--- AbstractWorker<MessagePort, Data, Response>
-
-- ThreadWorker
-
-Index
Constructors
-Properties
-Methods
-Constructors
-constructor
--- new
Thread Worker<Data, Response>(fn: ((data: Data) => Response), opts?: WorkerOptions): ThreadWorker<Data, Response>
--
-
-
-
-
-
-
Constructs a new poolifier thread worker.
-Type Parameters
---
-
--
-
Data = unknown
Response = unknown
Parameters
---
-
-
--
-
fn: ((data: Data) => Response)
-Function processed by the worker when the pool's
-execution
function is invoked.--
-
-- (data: Data): Response
--
-
-
-
Parameters
---
-
data: Data
Returns Response
opts: WorkerOptions = {}
-Options for the worker.
-Returns ThreadWorker<Data, Response>
Properties
- Interval
-Protected
Optional
Readonly
aliveHandler id of the
-aliveInterval
worker alive check. Main
-Protected
Readonly
isWhether this is the main worker or not.
- Task Timestamp
-Protected
lastTimestamp of the last task processed by this worker.
- Worker
-Protected
mainReference to main worker.
-
-Protected
Readonly
optsOptions for the worker.
-Methods
-async Id
--- async
Id(): number
--
-
-
-
Returns
The unique
-asyncId
assigned to the resource.Returns number
bind
--- bind<Func>(fn: Func): Func & {
--
-
-
-
-
-
-
    asyncResource: AsyncResource;
}
Binds the given function to execute to this
-AsyncResource
's scope.The returned function will have an
- -asyncResource
property referencing -theAsyncResource
to which the function is bound.Since
v14.8.0, v12.19.0
-Type Parameters
---
-
Func extends ((...args: any[]) => any)
Parameters
---
-
fn: Func
-The function to bind to the current
-AsyncResource
.Returns Func & {
    asyncResource: AsyncResource;
}
Alive
-Protected
check-- check
Alive(): void
--
-
-
Checks if the worker should be terminated, because its living too long.
-Returns void
emit Destroy
--- emit
Destroy(): ThreadWorker<Data, Response>
--
-
Call all
destroy
hooks. This should only ever be called once. An error will +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
Index
Constructors
Properties
Accessors
Methods
Constructors
constructor
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
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
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 TaskFunctionOperationResult
Whether the task function was added or not.
+async Id
Returns number
The unique
+asyncId
assigned to the resource.bind
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
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 ThreadWorker<Data, Response>
Main Worker
-Protected
get-- get
Main Worker(): MessagePort
--
-
-
Returns the main worker.
- -Returns
Reference to the main worker.
-Returns MessagePort
Error
-Protected
handle-- handle
Error(e: string | Error): string
--
-
-
-
-
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
-The error raised by the worker.
-Returns string
Listener
-Protected
message-- message
Listener(message: MessageValue<Data, MessagePort>, fn: ((data: Data) => Response)): void
--
-
-
-
-
Worker message listener.
-Parameters
---
-
--
-
-
message: MessageValue<Data, MessagePort>
-Message received.
-fn: ((data: Data) => Response)
-Function processed by the worker when the pool's
-execution
function is invoked.--
-
-- (data: Data): Response
--
-
-
-
Parameters
---
-
data: Data
Returns Response
Returns void
-Protected
run-- run(fn: ((data?: Data) => Response), message: MessageValue<Data, unknown>): void
--
-
-
-
-
Runs the given function synchronously.
-Parameters
---
-
-
--
-
fn: ((data?: Data) => Response)
-Function that will be executed.
---
-
-- (data?: Data): Response
--
-
-
-
Parameters
---
-
Optional
data: DataReturns Response
message: MessageValue<Data, unknown>
-Input data for the given function.
-Returns void
Async
-Protected
run-- run
Async(fn: ((data?: Data) => Promise<Response>), message: MessageValue<Data, unknown>): void
--
-
-
-
-
Runs the given function asynchronously.
-Parameters
---
-
-
--
-
fn: ((data?: Data) => Promise<Response>)
-Function that will be executed.
---
-
-- (data?: Data): Promise<Response>
--
-
-
-
Parameters
---
-
Optional
data: DataReturns Promise<Response>
message: MessageValue<Data, unknown>
-Input data for the given function.
-Returns void
run In Async Scope
--- run
In Async Scope<This, Result>(fn: ((this: This, ...args: any[]) => Result), thisArg?: This, ...args: any[]): Result
--
-
Call the provided function with the provided arguments in the execution context +
Returns ThreadWorker<Data, Response>
A reference to
+asyncResource
.Protected
getReturns the main worker.
+Returns MessagePort
Reference to the main worker.
+Throws
https://nodejs.org/api/errors.html#class-error If the main worker is not set.
+Protected
handleHandles 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.
+Protected
handleHandles a kill message sent by the main worker.
+Parameters
message: MessageValue<Data, unknown>
Returns void
Protected
handleHandles the ready message sent by the main worker.
+Parameters
message: MessageValue<Data, unknown>
The ready message.
+Returns void
Protected
handleParameters
message: MessageValue<Data, unknown>
Returns void
has Task Function
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
Lists the names of the worker's task functions.
+Returns string[]
The names of the worker's task functions.
+Protected
messageWorker message listener.
+Parameters
message: MessageValue<Data, unknown>
The received message.
+Returns void
remove Task Function
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
runRuns the given task.
+Parameters
task: Task<Data>
The task to execute.
+Returns void
Protected
runRuns 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
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.
- -Since
v9.6.0
-Type Parameters
---
-
--
-
This
Result
Parameters
---
-
-
--
-
--
-
fn: ((this: This, ...args: any[]) => Result)
-The function to call in the execution context of this async resource.
---
-
-- (this: This, ...args: any[]): 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
To Main Worker
-Protected
send-- send
To Main Worker(message: MessageValue<Response, unknown>): void
--
-
-
-
-
-
Inherit Doc
Parameters
---
-
message: MessageValue<Response, unknown>
Returns void
trigger Async Id
--- trigger
Async Id(): number
--
-
-
-
Returns
The same
-triggerAsyncId
that is passed to theAsyncResource
constructor.Returns number
-Static
bind-- bind<Func, ThisArg>(fn: Func, type?: string, thisArg?: ThisArg): Func & {
--
-
-
-
-
-
-
    asyncResource: AsyncResource;
}
Binds the given function to the current execution context.
-The returned function will have an
- -asyncResource
property referencing -theAsyncResource
to which the function is bound.Since
v14.8.0, v12.19.0
-Type Parameters
---
-
--
-
Func extends ((this: ThisArg, ...args: any[]) => 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 & {
    asyncResource: AsyncResource;
}
-
-Settings
Member Visibility
Theme
Generated using TypeDoc
Type Parameters
This
Result
Parameters
fn: ((this, ...args) => Result)
The function to call in the execution context of this async resource.
+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
+