repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' of github.com:poolifier/poolifier
[poolifier.git]
/
src
/
pools
/
worker.ts
diff --git
a/src/pools/worker.ts
b/src/pools/worker.ts
index 1de3cf09b6932053605efd6cc4719bfbe8bcf14c..1d0c4e22e47f073384bdf8c69e3c477ea9cb1d2b 100644
(file)
--- a/
src/pools/worker.ts
+++ b/
src/pools/worker.ts
@@
-2,6
+2,11
@@
import type { MessageChannel } from 'node:worker_threads'
import type { CircularArray } from '../circular-array'
import type { Task } from '../utility-types'
import type { CircularArray } from '../circular-array'
import type { Task } from '../utility-types'
+/**
+ * Callback invoked when the worker has started successfully.
+ */
+export type OnlineHandler<Worker extends IWorker> = (this: Worker) => void
+
/**
* Callback invoked if the worker has received a message.
*/
/**
* Callback invoked if the worker has received a message.
*/
@@
-18,11
+23,6
@@
export type ErrorHandler<Worker extends IWorker> = (
error: Error
) => void
error: Error
) => void
-/**
- * Callback invoked when the worker has started successfully.
- */
-export type OnlineHandler<Worker extends IWorker> = (this: Worker) => void
-
/**
* Callback invoked when the worker exits successfully.
*/
/**
* Callback invoked when the worker exits successfully.
*/
@@
-141,10
+141,6
@@
export interface WorkerInfo {
* Task function names.
*/
taskFunctions?: string[]
* Task function names.
*/
taskFunctions?: string[]
- /**
- * Message channel.
- */
- messageChannel?: MessageChannel
}
/**
}
/**
@@
-215,6
+211,10
@@
export interface IWorkerNode<Worker extends IWorker, Data = unknown> {
* Worker info.
*/
readonly info: WorkerInfo
* Worker info.
*/
readonly info: WorkerInfo
+ /**
+ * Message channel.
+ */
+ readonly messageChannel?: MessageChannel
/**
* Worker usage statistics.
*/
/**
* Worker usage statistics.
*/
@@
-229,7
+229,7
@@
export interface IWorkerNode<Worker extends IWorker, Data = unknown> {
* Enqueue task.
*
* @param task - The task to queue.
* Enqueue task.
*
* @param task - The task to queue.
- * @returns The task queue size.
+ * @returns The task
s
queue size.
*/
readonly enqueueTask: (task: Task<Data>) => number
/**
*/
readonly enqueueTask: (task: Task<Data>) => number
/**
@@
-243,7
+243,13
@@
export interface IWorkerNode<Worker extends IWorker, Data = unknown> {
*/
readonly clearTasksQueue: () => void
/**
*/
readonly clearTasksQueue: () => void
/**
- * Resets usage statistics .
+ * Whether the worker node has back pressure (i.e. its tasks queue is full).
+ *
+ * @returns `true` if the worker node has back pressure, `false` otherwise.
+ */
+ readonly hasBackPressure: () => boolean
+ /**
+ * Resets usage statistics.
*/
readonly resetUsage: () => void
/**
*/
readonly resetUsage: () => void
/**
@@
-251,7
+257,10
@@
export interface IWorkerNode<Worker extends IWorker, Data = unknown> {
*/
readonly closeChannel: () => void
/**
*/
readonly closeChannel: () => void
/**
- * Gets task worker usage statistics.
+ * Gets task function worker usage statistics.
+ *
+ * @param name - The task function name.
+ * @returns The task function worker usage statistics if the task function worker usage statistics are initialized, `undefined` otherwise.
*/
*/
- readonly getTaskWorkerUsage: (name: string) => WorkerUsage | undefined
+ readonly getTask
Function
WorkerUsage: (name: string) => WorkerUsage | undefined
}
}