Class AsyncPrioritizedQueue

An asynchronous, prioritized, observable and removable queue of worker functions.

Async - Workers are async functions. Next worker will be started when promise returned by previous worker resolves or rejects.

Prioritized - Each worker has a priority. 0 is highest, higher numbers means lower priority. Worker with higher priority will be executed first.

Observable - Calling the add method returns an observable. The worker will be queued on subscribing this observable. Multiple subscriptions lead to multiple executions of the worker. This observable will emit the result of the finished worker and then will complete immediately. It will send an error if the worker throws an error or rejects the returned promise.

Removable - The worker will be removed from the queue if the subscriber unsubscribes early, before the worker is started. If the subscriber unsubscribes late (the worker was already called but hasn't finished yet), it will not be cancelled. The caller will just miss the result.

Unhandled Errors - An error thrown by a worker will be passed through to the observable subscriber. If the subscriber unsubscribes during the execution of the worker, and the worker throws an error the error will be passed the the unhandledErrors observable (together with the worker function as a hint who throws that error).

Hierarchy

  • AsyncPrioritizedQueue

Constructors

Accessors

Methods

Constructors

Accessors

Methods

  • Creates an Observable for queuing the given worker with the given priority. Subscribe to add the worker to the queue. Multiple subscriptions will add the worker multiple times. Unsubscribe before completion to remove the worker from the queue.

    Observable emits the result of the worker and then completes immediately. Observable mirrors any error thrown by the worker.

    Type Parameters

    • T

    Parameters

    • worker: Worker<T>
    • priority: number

    Returns Observable<T>

Generated using TypeDoc