X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=docs%2Fclasses%2FThreadWorker.html;h=040d7c3e92338bb3bd24415e99f8a5a44b1bd4a8;hb=a34454964733f585af19a04f21f9e35eb18c77b1;hp=e90d1519081252311b951ac183d40e05f15c6822;hpb=d0f1dce33156fdb99f0ca3627839001909419497;p=poolifier.git diff --git a/docs/classes/ThreadWorker.html b/docs/classes/ThreadWorker.html index e90d1519..040d7c3e 100644 --- a/docs/classes/ThreadWorker.html +++ b/docs/classes/ThreadWorker.html @@ -1,83 +1,525 @@ -
The function to bind to the current execution context.
+Optional
type: stringAn optional name to associate with the underlying AsyncResource
.
Optional
thisArg: ThisArgGenerated using TypeDoc
A thread worker used by a poolifier
-ThreadPool
.When this worker is inactive for more than the given
maxInactiveTime
, ++- Preparing search index...
+- The search index is not available
poolifier+- poolifier
+- ThreadWorker
+Class 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.of data this worker receives from pool's execution. This can only be serializable data.
-of response the worker sends back to the main thread. This can only be serializable data.
-Alessandro Pio Ardizio
-0.0.1
-Type parameters
Data = unknown
Response = unknown
Hierarchy
Index
Constructors
Properties
Methods
Constructors
constructor
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.Parameters
data: Data
Returns Response
opts: WorkerOptions = {}
Options for the worker.
-Returns ThreadWorker<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 + +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 & {
+-
+
- since
    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.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 + +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 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
.Protected get Main Worker
Returns the main worker.
-Returns MessagePort
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
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
+-
+
- 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 + +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 & {
+-
+
- since
    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.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
Since
v14.8.0, v12.19.0
+