start
The start
method begins the 'ticks' of the Manager
, which will start the process of managing the schedules, timeouts, and retries of tasks.
start(): Manager
Note that this method will not immediately run any due task runs. Instead it will wait for the next tickInterval to pass before doing so. This means that you can expect this method to return very quickly.
Though you can stop and start the Manager
as many times as you like, it is expected that you will only start it once at the beginning of your app's lifecycle, and then stop it when it closes and you are cleaning up.
Example
This example registers a task that is then scheduled to run. The Manager
is then started, and one tickInterval
later, the task run starts.
import {createManager} from 'tinytick';
const manager = createManager();
manager.setTask('ping', async () => await fetch('https://example.org'));
manager.scheduleTaskRun('ping');
console.log(manager.getRunningTaskRunIds().length);
// -> 0
manager.start();
// ... wait 100ms (the Manager tickInterval) for task run to start
console.log(manager.getRunningTaskRunIds().length);
// -> 1
Since
v1.0.0