Queue instance is a event emitter. To listen to event register a listener:
const listener = () => {};
q.addEventListener("event name", listener);
To remove a listener call the function returned from addEventListener
or use removeEventListener
:
const listener = () => {};
const unregister = q.addEventListener("event name", listener);
unregister();
// or:
q.addEventListener("event name", listener);
q.removeEventListener("event name", listener);
You can also attach your listener for single occurrence of event - it will be automatically removed after first event of given name occurs.
q.addEventListenerOnce("event name", listener);
You can remove once
listeners the same way as standard listener.
When a queue is destroyed - all listeners are removed automatically.
You can use aliases for adding/removing events:
on
➡ addEventListener
off
➡ removeEventListener
once
➡ addEventListenerOnce
Events are exposed on named export:
import { EVENTS } from "queue-system";
q.addEventListener(EVENTS.TASK_ADD, listener);
Always use constants when adding/removing a listener.
Emitted when task is added into the queue.
Parameters:
{Task} - newly added task instance
Emitted when task is removed from the queue either by request or automatically when task is fulfilled.
Parameters:
{Task} - removed task instance
Emitted when task function is started.
Parameters:
{Task} - started task instance
Emitted when task function is finished.
Parameters:
{Task} - finished task instance
Emitted when task function is finished and it was successful.
Parameters:
{Task} - successful task instance
Emitted when task function is finished and it was unsuccessful.
Parameters:
{Task} - unsuccessful task instance
Emitted when task function thrown an error before returning.
Parameters:
{Task} - task instance that thrown
Emitted when queue size had changed (task is added or removed). Useful for tracking when queue is done/empty.
Parameters:
{number} - queue size AFTER task is added or removed
Emitted when queue size had changed (task is added or removed).
Parameters:
{Array<Task>} - array of tasks in order how they exists in the queue; keep in mind that tasks in progress are still listed on this array
Generated using TypeDoc