Skip to content

ITaskOptions

Defined in: src/types/ITaskOptions.ts:76

Options for a Task.

TData = any

optional enabled?: boolean

Defined in: src/types/ITaskOptions.ts:13

Whether the task is currently enabled. This gives manual control over execution: while false, the task bypasses its callback. Default: true.

ITaskBaseOptions.enabled


optional lead?: boolean

Defined in: src/types/ITaskOptions.ts:20

Whether to run the task once immediately when the timer starts (the leading edge), in addition to its normal tick schedule — instead of waiting a full interval for the first tick. Ignored while a future startDate has not been reached. Applies on start() only. Default: false.

ITaskBaseOptions.lead


optional data?: TData

Defined in: src/types/ITaskOptions.ts:26

Arbitrary user data attached to the task, available as task.data in the callback and event listeners. Type it via the TData parameter, e.g. timer.get<MyType>(id). Default: undefined.

ITaskBaseOptions.data


optional tickDelay?: number

Defined in: src/types/ITaskOptions.ts:31

Number of ticks to wait before running the task for the first time. Default: 0.

ITaskBaseOptions.tickDelay


optional tickInterval?: number

Defined in: src/types/ITaskOptions.ts:37

Tick interval the task runs on. The unit is ticks, not milliseconds: with a timer interval of 1000 ms, a tickInterval of 5 runs the task every 5 seconds. Default: 1.

ITaskBaseOptions.tickInterval


optional totalRuns?: number | null

Defined in: src/types/ITaskOptions.ts:42

Total number of times the task should run. 0 or null means unlimited, until stopDate is reached or the timer stops. Default: null.

ITaskBaseOptions.totalRuns


optional startDate?: number | Date

Defined in: src/types/ITaskOptions.ts:47

Date/time (or timestamp) to start executing the task. If omitted, the task runs on its tick interval right after the timer starts.

ITaskBaseOptions.startDate


optional stopDate?: number | Date

Defined in: src/types/ITaskOptions.ts:53

Date/time (or timestamp) to stop executing the task. If totalRuns is reached first, the task is considered completed regardless. If omitted, the task runs until totalRuns is fulfilled or the timer stops.

ITaskBaseOptions.stopDate


optional defer?: boolean

Defined in: src/types/ITaskOptions.ts:60

Whether to defer the callback to the next event-loop turn (via setImmediate) before executing, so it yields instead of running inline on the tick. Useful when the task synchronously blocks the event loop without doing I/O or using JS timers. Default: false.

ITaskBaseOptions.defer


optional removeOnCompleted?: boolean

Defined in: src/types/ITaskOptions.ts:66

Whether to remove the task (freeing memory) once it has completed its runs. For this to take effect, the task must have totalRuns and/or stopDate configured. Default: false.

ITaskBaseOptions.removeOnCompleted


callback: TaskCallback<TData>

Defined in: src/types/ITaskOptions.ts:70

Callback executed on each run of the task. See TaskCallback.

ITaskBaseOptions.callback


optional id?: string

Defined in: src/types/ITaskOptions.ts:82

Unique ID of the task. Required when constructing a Task directly; may be omitted when adding via TaskTimer.add, in which case a unique task{n} ID is generated.