addStatusListener
The addStatusListener
method registers a listener function with the Manager
that will be called when the Manager
changes status from stopped to started, or vice-versa.
addStatusListener(listener: StatusListener): string
Type | Description | |
---|---|---|
listener | StatusListener | The function that will be called when the |
returns | string | A unique |
The provided listener is a StatusListener
function, and will be called with a reference to the Manager
and the new status.
Example
This example registers a listener that responds to the Manager
's status changes.
import {createManager} from 'tinytick';
const manager = createManager();
const listenerId = manager.addStatusListener((manager, status) => {
console.log(`Manager status changed to: ${status}`);
});
manager.start();
// -> 'Manager status changed to: 1'
manager.stop();
// -> 'Manager status changed to: 2'
// ... wait 100ms for the final tick to stop the manager
// -> 'Manager status changed to: 0'
manager.delListener(listenerId);
Since
v1.2.0