Options
All
  • Public
  • Public/Protected
  • All
Menu

A Promise-based blocking queue.

Type parameters

  • T

Hierarchy

  • AsyncQueue

Index

Constructors

  • Type parameters

    • T

    Returns AsyncQueue<T>

Properties

awaiters: Awaiter<T>[]
closed: boolean
items: T[]

Methods

  • add(item: T): void
  • Adds an item at the end of a queue. If the queue was empty and there are any pending requests from take(), the first one receives the item. If the queue has been closed, nothing happens.

    Parameters

    • item: T

      The item to add.

    Returns void

  • close(): void
  • Signals that the queue ends permanently after its current position. After calling close(), take() will still consume any items that already exist in the queue, but once it is empty, take() returns an error. No more items can be added.

    Returns void

  • isEmpty(): boolean
  • Tests whether the queue is empty.

    Returns boolean

    True if the queue is empty.

  • length(): number
  • Returns the current number of items in the queue.

    Returns number

    The length of the queue.

  • take(): Promise<T>
  • Attempts to consume an item from the queue in FIFO order, waiting until there is one, unless the queue is closed.

    Returns Promise<T>

    A Promise that is resolved with the first item in the queue once it is available, removing the item. If the queue is empty and has been closed with close(), the Promise is rejected instad.

  • closedError(): Error
  • Returns Error

Generated using TypeDoc