Simple task queue. Each task is awaited and run in turn.
The TaskQueueMutable is shared across your code, so you don't create it directly. Rather, use:
import { TaskQueueMutable } from "https://unpkg.com/ixfx/dist/flow.js"const queue = TaskQueueMutable.shared; Copy
import { TaskQueueMutable } from "https://unpkg.com/ixfx/dist/flow.js"const queue = TaskQueueMutable.shared;
import { TaskQueueMutable, sleep } from "https://unpkg.com/ixfx/dist/flow.js"const queue = TaskQueueMutable.shared;q.enqueue(async () => { // Takes one second to run await sleep(1000);}); Copy
import { TaskQueueMutable, sleep } from "https://unpkg.com/ixfx/dist/flow.js"const queue = TaskQueueMutable.shared;q.enqueue(async () => { // Takes one second to run await sleep(1000);});
You can listen to events from the TaskQueue:
TaskQueueMutable.shared.addEventListener(`started`, () => { // Queue was empty, now started processing});TaskQueueMutable.shared.addEventListener(`empty`, () => { // Queue has finished processing all items}); Copy
TaskQueueMutable.shared.addEventListener(`started`, () => { // Queue was empty, now started processing});TaskQueueMutable.shared.addEventListener(`empty`, () => { // Queue has finished processing all items});
Static
Readonly
Returns true if queue is empty
Number of items in queue
Adds event listener.
Events
Event name
Event handler
Error if emitter is disposed
Clears all tasks, and stops any scheduled processing. Currently running tasks will continue.
Adds a task. This triggers processing loop if not already started.
queue.add(async () => { await sleep(1000);}); Copy
queue.add(async () => { await sleep(1000);});
Task to run
Protected
Fire event
Type of event
Arguments for event
Remove event listener
Simple task queue. Each task is awaited and run in turn.
The TaskQueueMutable is shared across your code, so you don't create it directly. Rather, use:
Example: Usage
You can listen to events from the TaskQueue: