Pausing Task
Kronash provides the ability to pause a currently running task, something not directly manageable with JavaScript's built-in setTimeout
or setInterval
functions. This feature is especially useful when you want to halt the operation of a task temporarily and plan to resume it later.
To pause a task, you can use the pause
method on your Kronash instance, passing the name of the task you want to pause as an argument:
kronash.pause('myTask');
// or
kronash.create(options).start().pause();
In this example, the task with the name 'myTask'
would be paused if it's currently running.
Notes
Before a task can be paused, the following conditions must be met:
-
The task must exist: You cannot pause a task that hasn't been created. Be sure to create the task with
kronash.create()
method before attempting to pause it. -
Task must be in the
running
state: A task can only be paused if it is currently running. If a task is in any other state (idle
,paused
,stopped
,finished
), you can't pause it.
If these conditions aren't met when you call kronash.pause()
, an error will be thrown. Make sure these conditions are fulfilled to successfully pause a task.
After pausing, the task's state will be paused
, and its remainingTime
will be updated to reflect the amount of time left until the task would 'tick'. You can later resume the operation of a paused task using the resume
method.