TinyTick logoTinyTick

stop

The stop method stops the 'ticks' of the Manager, which will cease the process of managing the schedules, timeouts, and retries of tasks.

stop(force?: boolean): Manager
TypeDescription
force?boolean

Whether to stop the Manager immediately instead of waiting for all scheduled task runs to complete.

returnsManager

A reference to the Manager.

Note that this will not abort any task runs currently underway, and by default, it will wait for all future scheduled tasks to complete too. (However, during this 'stopping' phase, no new task runs can be scheduled, in case a task recursively schedules a new run of itself and the Manager can therefore never stop).

You can also use the optional force parameter to stop the Manager immediately. This will still not abort any task runs currently underway, but it will not wait for future scheduled tasks to complete. These will remain in the schedule list and will be run if the Manager is ever started again.

Example

This example registers a task that is then scheduled to run twice. The Manager is started, and one tickInterval later, stopped again. With the force flag set, only the first task run is executed. If it had been omitted or false, the Manager would only have stopped after the second outstanding task had run.

import {createManager} from 'tinytick';

const manager = createManager();
manager.setTask('ping', async () => await fetch('https://example.org'));
manager.scheduleTaskRun('ping');
manager.scheduleTaskRun('ping', '', 200); // In two tick intervals' time

console.log(manager.getScheduledTaskRunIds().length);
// -> 2
console.log(manager.getRunningTaskRunIds().length);
// -> 0

manager.start();
// ... wait 100ms (the Manager tickInterval) for task run to start

console.log(manager.getScheduledTaskRunIds().length);
// -> 1
console.log(manager.getRunningTaskRunIds().length);
// -> 1

manager.stop(true);
// ... wait 100ms; the first task run will end but the second won't start

console.log(manager.getScheduledTaskRunIds().length);
// -> 1
console.log(manager.getRunningTaskRunIds().length);
// -> 0

Since

v1.0.0