Skip to content

TaskCallback

TaskCallback<TData> = (task, done?) => void | Promise<unknown>

Defined in: src/types/TaskCallback.ts:23

Callback executed on each run of a task. The task itself is passed as the first argument. For an async task, either return a Promise or call the done function passed as the second argument when the work is finished.

TData = any

Task<TData>

The task being executed.

() => void

Marks an async task as finished. Omit for sync tasks or when returning a Promise.

void | Promise<unknown>

// sync
timer.add(task => console.log(task.currentRuns));
// async via done()
timer.add((task, done) => fs.readFile(path, () => done()));
// async via Promise
timer.add(task => readFileAsync(path).then(process));