A queue implementation where the reader promises block until new data is available.

Type Parameters

  • T

Constructors

  • Constructs a new blocking queue.

    Type Parameters

    • T

    Parameters

    • maxDataQueueLength: number = Number.POSITIVE_INFINITY
    • maxPendingPromiseCount: number = Number.POSITIVE_INFINITY
    • defaultTimeout: number = Number.POSITIVE_INFINITY

      Default timeout used for remove() call when no timeout was specified. Defaults to Number.POSITIVE_INFINITY.

    Returns default<T>

Accessors

  • get data(): T[]
  • Get a copy of the internal data buffer.

    Note that the elements themselves are not copied, so if the contents are not native types, do not modify them.

    Returns T[]

  • get pendingPromiseCount(): number
  • Get the number of pending promises if no elements are in the queue.

    Returns number

Methods

  • Add data to the queue.

    This will throw if the queue is full.

    Parameters

    • data: T

    Returns void

  • Cancels all pending remove promises.

    Parameters

    • Optionalerr: Error

    Returns void

  • Add data to the queue but insert it at given index.

    0 means that the element becomes the first value in the queue. buffer.length means that the element will become the last element. Negative values means that it is inserted from behind (same as array.slice start parameter)

    This will throw if the queue is full.

    Parameters

    • data: T
    • index: number

    Returns void

  • Add data to the queue but insert sorted.

    This requires, that the data was already sorted. If elements that are equal are found, the element is inserted after the equal ones.

    This will throw if the queue is full.

    Parameters

    • data: T
    • compareFn: ((a: T, b: T) => number)

      like the array.sort() compare function.

        • (a, b): number
        • Parameters

          Returns number

    Returns void

  • Get element from queue.

    If no element is in the queue, then the promise will not resolve, until there is.

    Parameters

    • Optionaltimeout: number

      Timeout as unsigned 32-bit integer or Number.POSITIVE_INFINITY. If undefined use the default value passed to the constructor.

    Returns Promise<T>