Documentation
Guide
Stopping Task

Stopping Task

Kronash makes it easy to stop a task that is currently running, giving you an increased control over the task operations in your application.

Stopping a task halts its execution and resets it to its initial state, but unlike clear, it doesn't remove the task.

To stop a task, use the stop method from your Kronash instance and pass the name of the task you want to stop:

kronash.stop('myTask');
// or
kronash.create(options).start().stop();

In this example, the task with the name 'myTask' will be stopped if it's currently running.

Notes

Before a task can be stopped, the following conditions must be met:

  1. The task must exist: You can't stop a task that hasn't been created yet. So, make sure you've created the task with kronash.create() before attempting to stop it.

  2. Task must be in the running state: A task can only be stopped if it is currently running. If a task is in any other state (idle, paused, stopped, finished), it cannot be stopped.

If these conditions aren't met when you call kronash.stop(), an error will be thrown. Ensure that these conditions are fulfilled to successfully stop a task.

After stopping, the task's state will be stopped, and its remainingTime will revert to null. You can then start the task again using the start method, which will reset its startedAt timestamp and run the task from the beginning.