Class DeferredWorkQueue<TRequest, TResolve>

Deferred work processor class which queues work items and returns an awaitable deferred promise. This class supports bulkification of otherwise singular work items. A processor function/delegate is passed which will process all queue items in bulk. Optionally a chunk size can be specified which determines the size of the chunks passed to the processor delegate.

Type Parameters

  • TRequest

  • TResolve

Hierarchy

  • DeferredWorkQueue

Constructors

  • Type Parameters

    • TRequest

    • TResolve

    Parameters

    • processor: ((requests) => Promise<WorkItemResult<undefined | TResolve>[]>)
        • (requests): Promise<WorkItemResult<undefined | TResolve>[]>
        • Parameters

          • requests: TRequest[]

          Returns Promise<WorkItemResult<undefined | TResolve>[]>

    • Optional thisArg: any
    • processWaitTime: number = 50

      Time to wait until executing the queued lookups

    • chunkSize: undefined | number = undefined

      Size of the chunks

    Returns DeferredWorkQueue<TRequest, TResolve>

Properties

chunkSize: undefined | number = undefined

Size of the chunks

processWaitTime: number = 50

Time to wait until executing the queued lookups

processing: boolean = false
processingQueue: Map<number, {
    deferred: DeferredPromise<undefined | TResolve>;
    id: number;
    request: TRequest;
}> = ...

Set of items that is currently being processed

Type declaration

  • deferred: DeferredPromise<undefined | TResolve>
  • id: number
  • request: TRequest
processor: ((requests) => Promise<WorkItemResult<undefined | TResolve>[]>)

Type declaration

    • (requests): Promise<WorkItemResult<undefined | TResolve>[]>
    • Processor fn

      Parameters

      • requests: TRequest[]

      Returns Promise<WorkItemResult<undefined | TResolve>[]>

queueTimer?: Timeout
requestIdRef: number = 0

Used to keep track of work items

requestQueue: {
    deferred: DeferredPromise<undefined | TResolve>;
    id: number;
    request: TRequest;
}[] = ...

Queue with items that are going to be worked upon

Type declaration

  • deferred: DeferredPromise<undefined | TResolve>
  • id: number
  • request: TRequest

Methods

  • Find the first item that matches the predicate and returns the associated promise; use this to avoid enqueued ing the same item multiple items

    Parameters

    • predicate: ((item) => any)
        • (item): any
        • Parameters

          • item: TRequest

          Returns any

    Returns undefined | DeferredPromise<undefined | TResolve>