Skip to content

ITaskBaseOptions

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

Base options for a Task, shared by task creation and Task.reset.

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.


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.


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.


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.


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.


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.


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.


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.


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.


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.


callback: TaskCallback<TData>

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

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