Class Queue

A queue / task manager.

Example

import { Queue } from "@egomobile/queue";

let queue!: Queue;

async function main() {
queue = new Queue();

// first register the task
queue.register({
'myTask1': async (context) => {
console.log("Executing task", context.key, "with data", context.data);
}
});

// and then enqueue it
// while the underlying storage is
// responsable for the execution
await queue.enqueue('myTask1', {
data: {
foo: 'bar',
buzz: 4242
}
});
}

main().catch(console.error);

Hierarchy

  • Queue

Constructors

Properties

_errorHandlers: QueueErrorHandler[] = []
_isRunning: boolean = false
_tasks: Record<string, QueueTask> = {}

Accessors

  • get isRunning(): boolean
  • Gets if queue is running or not.

    Returns

    A value, which indicates if queue is running or not.

    Returns boolean

Methods

  • Queues a task.

    Example

    const queue = new Queue();

    /// ... register 'myTask1'

    // enqueue (and execute) without data
    await queue.enqueue('myTask1');
    // with data
    await queue.enqueue('myTask1', {
    data: { foo: 'bar' }
    });

    Returns

    The promise with the context.

    Parameters

    • key: string

      The key / ID of the task.

    • Optional options: Nilable<IQueueEnqueueOptions>

      Additional and custom options.

    Returns Promise<IQueueTaskContext>

  • Starts the queue.

    Returns

    A promise, which indicates if operation was successful or not.

    Returns Promise<boolean>

  • Stops the queue.

    Returns

    A promise, which indicates if operation was successful or not.

    Returns Promise<boolean>

Generated using TypeDoc