repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
test: use arrow noop task function
[poolifier.git]
/
src
/
pools
/
worker.ts
diff --git
a/src/pools/worker.ts
b/src/pools/worker.ts
index 05f6606edde672db081d9f392e9584ebc7a917f7..35d9f755bc3f9d4d321c8ac7b999261a3e1d613a 100644
(file)
--- a/
src/pools/worker.ts
+++ b/
src/pools/worker.ts
@@
-1,7
+1,8
@@
-import type { MessageChannel, WorkerOptions } from 'node:worker_threads'
import type { EventEmitter } from 'node:events'
import type { EventEmitter } from 'node:events'
+import type { MessageChannel, WorkerOptions } from 'node:worker_threads'
+
import type { CircularArray } from '../circular-array.js'
import type { CircularArray } from '../circular-array.js'
-import type { Task } from '../utility-types.js'
+import type { Task
, TaskFunctionProperties
} from '../utility-types.js'
/**
* Callback invoked when the worker has started successfully.
/**
* Callback invoked when the worker has started successfully.
@@
-133,10
+134,11
@@
export interface TaskStatistics {
/**
* Enumeration of worker types.
*/
/**
* Enumeration of worker types.
*/
-export const WorkerTypes = Object.freeze({
- thread: 'thread',
- cluster: 'cluster'
-} as const)
+export const WorkerTypes: Readonly<{ thread: 'thread', cluster: 'cluster' }> =
+ Object.freeze({
+ thread: 'thread',
+ cluster: 'cluster'
+ } as const)
/**
* Worker type.
/**
* Worker type.
@@
-171,9
+173,9
@@
export interface WorkerInfo {
*/
stealing: boolean
/**
*/
stealing: boolean
/**
- * Task function
nam
es.
+ * Task function
s properti
es.
*/
*/
- taskFunction
Names?: string
[]
+ taskFunction
sProperties?: TaskFunctionProperties
[]
}
/**
}
/**
@@
-235,6
+237,12
@@
export interface IWorker extends EventEmitter {
* @param handler - The event handler.
*/
readonly once: (event: string, handler: EventHandler<this>) => this
* @param handler - The event handler.
*/
readonly once: (event: string, handler: EventHandler<this>) => this
+ /**
+ * Calling `unref()` on a worker allows the thread to exit if this is the only
+ * active handle in the event system. If the worker is already `unref()`ed calling`unref()` again has no effect.
+ * @since v10.5.0
+ */
+ readonly unref?: () => void
/**
* Stop all JavaScript execution in the worker thread as soon as possible.
* Returns a Promise for the exit code that is fulfilled when the `'exit' event` is emitted.
/**
* Stop all JavaScript execution in the worker thread as soon as possible.
* Returns a Promise for the exit code that is fulfilled when the `'exit' event` is emitted.
@@
-259,6
+267,7
@@
export interface WorkerNodeOptions {
workerOptions?: WorkerOptions
env?: Record<string, unknown>
tasksQueueBackPressureSize: number | undefined
workerOptions?: WorkerOptions
env?: Record<string, unknown>
tasksQueueBackPressureSize: number | undefined
+ tasksQueueBucketSize: number | undefined
}
/**
}
/**
@@
-309,25
+318,13
@@
export interface IWorkerNode<Worker extends IWorker, Data = unknown>
* @returns The tasks queue size.
*/
readonly enqueueTask: (task: Task<Data>) => number
* @returns The tasks queue size.
*/
readonly enqueueTask: (task: Task<Data>) => number
- /**
- * Prepends a task to the tasks queue.
- *
- * @param task - The task to prepend.
- * @returns The tasks queue size.
- */
- readonly unshiftTask: (task: Task<Data>) => number
/**
* Dequeue task.
*
/**
* Dequeue task.
*
+ * @param bucket - The prioritized bucket to dequeue from. @defaultValue 0
* @returns The dequeued task.
*/
* @returns The dequeued task.
*/
- readonly dequeueTask: () => Task<Data> | undefined
- /**
- * Pops a task from the tasks queue.
- *
- * @returns The popped task.
- */
- readonly popTask: () => Task<Data> | undefined
+ readonly dequeueTask: (bucket?: number) => Task<Data> | undefined
/**
* Clears tasks queue.
*/
/**
* Clears tasks queue.
*/
@@
-338,10
+335,6
@@
export interface IWorkerNode<Worker extends IWorker, Data = unknown>
* @returns `true` if the worker node has back pressure, `false` otherwise.
*/
readonly hasBackPressure: () => boolean
* @returns `true` if the worker node has back pressure, `false` otherwise.
*/
readonly hasBackPressure: () => boolean
- /**
- * Resets usage statistics.
- */
- readonly resetUsage: () => void
/**
* Terminates the worker node.
*/
/**
* Terminates the worker node.
*/