X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=docs%2Fclasses%2FClusterWorker.html;h=198f20179cb872a754a0233e869e9f3922923962;hb=b4c2a50df77a5f3110d228436ce9f3008cbd8297;hp=ea6c5d88bab97a92d61cfe79e314f0c19a235b0f;hpb=d0f1dce33156fdb99f0ca3627839001909419497;p=poolifier.git diff --git a/docs/classes/ClusterWorker.html b/docs/classes/ClusterWorker.html index ea6c5d88..198f2017 100644 --- a/docs/classes/ClusterWorker.html +++ b/docs/classes/ClusterWorker.html @@ -1,83 +1,775 @@ -
The function to call in the execution context of this async resource.
+Rest
...args: any[]Rest
Optional
thisArg: ThisThe receiver to be used for the function call.
+Optional
Rest
...args: any[]Optional arguments to pass to the function.
+Rest
v9.6.0
+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.
+ +https://nodejs.org/api/errors.html#class-typeerror If the name
parameter is not a string or an empty string.
https://nodejs.org/api/errors.html#class-error If the name
parameter is the default task function reserved name.
https://nodejs.org/api/errors.html#class-error If the name
parameter is a non-existing task function.
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
Optional
thisArg: ThisArgOptional
v14.8.0, v12.19.0
+Generated using TypeDoc
A cluster worker used by a poolifier
-ClusterPool
.When this worker is inactive for more than the given
maxInactiveTime
, ++- Preparing search index...
+- The search index is not available
poolifier - v2.6.40+- poolifier
+- ClusterWorker
+Class ClusterWorker<Data, Response>
A cluster worker used by a poolifier
+ClusterPool
.When this worker is inactive for more than the given
maxInactiveTime
, it will send a termination request to its main worker.If you use a
-DynamicClusterPool
the extra workers that were created will be terminated, but the minimum number of workers will be guaranteed.of data this worker receives from pool's execution. This can only be serializable data.
-of response the worker sends back to the main worker. This can only be serializable data.
-Christopher Quadflieg
-2.0.0
-Type parameters
Data = unknown
Response = unknown
Hierarchy
Index
Constructors
Properties
Methods
Constructors
constructor
Constructs a new poolifier cluster 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.Parameters
data: Data
Returns Response
opts: WorkerOptions = {}
Options for the worker.
-Returns ClusterWorker<Data, Response>
Properties
Protected Optional Readonly alive Interval
Handler Id of the
-aliveInterval
worker alive check.Protected last Task Timestamp
Timestamp of the last task processed by this worker.
-Protected main Worker
Readonly opts
Methods
async Id
Returns number
The unique
-asyncId
assigned to the resource.bind
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.v14.8.0, v12.19.0
-Type parameters
Func: (...args: any[]) => any
Parameters
fn: Func
The function to bind to the current
-AsyncResource
.Returns Func & { asyncResource: AsyncResource }
Protected check Alive
Check to see if the worker should be terminated, because its living too long.
-Returns void
emit Destroy
Call all
destroy
hooks. This should only ever be called once. An error will +Author
Christopher Quadflieg
+ +Since
2.0.0
+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 worker. This can only be structured-cloneable data.
+Hierarchy
++- AbstractWorker<Worker, Data, Response>
+
+- ClusterWorker
+
+Index
Constructors
+Properties
+Accessors
+Methods
+Constructors
+constructor
++- new
Cluster Worker<Data, Response>(taskFunctions, opts?): ClusterWorker<Data, Response>
+-
+
+
+
+
+
+
Constructs a new poolifier cluster 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 ClusterWorker<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.
+
+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. +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(): ClusterWorker<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 ClusterWorker<Data, Response>
A reference to
-asyncResource
.Protected get Main Worker
Returns the main worker.
-Returns Worker
Reference to the main worker.
-Protected handle Error
Handle 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
Message of the error.
-Protected run
Run the given function synchronously.
-Parameters
fn: (data?: Data) => Response
Function that will be executed.
-Parameters
Optional data: Data
Returns Response
value: MessageValue<Data, unknown>
Input data for the given function.
-Returns void
Protected run Async
Run the given function asynchronously.
-Parameters
fn: (data?: Data) => Promise<Response>
Function that will be executed.
-Parameters
Optional data: Data
Returns Promise<Response>
value: MessageValue<Data, unknown>
Input data for the given function.
-Returns void
run In Async Scope
Call the provided function with the provided arguments in the execution context +
Returns ClusterWorker<Data, Response>
A reference to
+ + +asyncResource
. Main Worker
+Protected
get+- get
Main Worker(): Worker
+-
+
+
+
Returns the main worker.
+Returns Worker
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(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
+-
+
- since
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.
-v9.6.0
-Type parameters
This
Result
Parameters
fn: (...args: any[]) => Result
The function to call in the execution context of this async resource.
-Parameters
Rest ...args: any[]
Returns Result
Optional thisArg: This
The receiver to be used for the function call.
-Rest ...args: any[]
Optional arguments to pass to the function.
-Returns Result
Protected send To Main Worker
Send a message to the main worker.
-Parameters
message: MessageValue<Response, unknown>
The response message.
-Returns void
trigger Async Id
Returns number
The same
-triggerAsyncId
that is passed to theAsyncResource
constructor.Static bind
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.v14.8.0, v12.19.0
-Type parameters
Func: (...args: any[]) => any
ThisArg
Parameters
fn: Func
The function to bind to the current execution context.
-Optional type: string
An optional name to associate with the underlying
-AsyncResource
.Optional thisArg: ThisArg
Returns Func & { asyncResource: AsyncResource }
Generated using TypeDoc