2 * Enumeration of kill behaviors.
4 export const KillBehaviors
= Object.freeze({
6 * If `currentTime - lastActiveTime` is greater than `maxInactiveTime` but a task is still running, then the worker **wont** be deleted.
10 * If `lastActiveTime` is greater than `maxInactiveTime` but a task is still running, then the worker will be deleted.
18 export type KillBehavior
= keyof
typeof KillBehaviors
21 * Detects whether the given value is a kill behavior or not.
23 * @template KB Which specific KillBehavior to test against.
24 * @param killBehavior Which kind of kill behavior to detect.
25 * @param value Any value.
26 * @returns `true` if `value` was strictly equals to `killBehavior`, otherwise `false`.
28 export function isKillBehavior
<KB
extends KillBehavior
> (
32 return value
=== killBehavior
36 * Options for workers.
38 export interface WorkerOptions
{
40 * Maximum waiting time in milliseconds for tasks.
42 * After this time, newly created workers will be terminated.
43 * The last active time of your worker unit will be updated when a task is submitted to a worker or when a worker terminate a task.
45 * - If `killBehavior` is set to `KillBehaviors.HARD` this value represents also the timeout for the tasks that you submit to the pool,
46 * when this timeout expires your tasks is interrupted and the worker is killed if is not part of the minimum size of the pool.
47 * - If `killBehavior` is set to `KillBehaviors.SOFT` your tasks have no timeout and your workers will not be terminated until your task is completed.
51 maxInactiveTime
?: number
53 * Whether your worker will perform asynchronous or not.
59 * `killBehavior` dictates if your async unit (worker/process) will be deleted in case that a task is active on it.
61 * - SOFT: If `currentTime - lastActiveTime` is greater than `maxInactiveTime` but a task is still running, then the worker **won't** be deleted.
62 * - HARD: If `lastActiveTime` is greater than `maxInactiveTime` but a task is still running, then the worker will be deleted.
64 * This option only apply to the newly created workers.
66 * @default KillBehaviors.SOFT
68 killBehavior
?: KillBehavior