Options
All
  • Public
  • Public/Protected
  • All
Menu

Type parameters

  • T

Hierarchy

  • AsyncQueue

Implements

Index

Constructors

constructor

Properties

Private buffer

buffer: T[] = ...

Private elementSem

elementSem: ISemaphore = ...

Methods

[Symbol.asyncIterator]

  • [Symbol.asyncIterator](): AsyncIterableIterator<T>

dequeue

  • dequeue(): Promise<T>
  • Dequeue an element, waiting for data to be available if necessary.

    Returns Promise<T>

    A promise which is fulfilled when an element (as queued by queue()) becomes available. If multiple dequeus() are issued sequentially, it is implementation-defined whether they are fulfilled in the same order or not. However, the data is still retrieved in FIFO fashion, meaning the first fulfilled promise gets the first element, the second fulfilled the second one and so forth.

poll

  • poll(): T

queue

  • queue(data: T): void

queueAll

  • queueAll(iterable: Iterable<T>): void

queueAllAsync

  • queueAllAsync(iterable: AsyncIterable<T>): Promise<void>

size

  • size(): number
  • Return the current size at the moment of the call.

    Even though code like

    if (queue.size() >= 1) {
      const element = queue.poll();
    }
    

    is technically not wrong (due to JS' execution model), users are advised to avoid this pattern. Instead, users are encouraged to

    • in cases where waiting for a promise is impossible, to use poll and catch the exception,
    • or to use dequeue with JS' await or queue.dequeue().then(...).

    Returns number

Generated using TypeDoc