Skip to main content
Module

x/async/mod.ts>Queue

🦕 Asynchronous primitive modules for Deno.
Latest
class Queue
import { Queue } from "https://deno.land/x/async@v2.1.0/mod.ts";

A queue implementation that allows for adding and removing elements, with optional waiting when popping elements from an empty queue.

import { assertEquals } from "https://deno.land/std@0.211.0/assert/mod.ts";
import { Queue } from "https://deno.land/x/async@v2.1.0/queue.ts";

const queue = new Queue<number>();
queue.push(1);
queue.push(2);
queue.push(3);
assertEquals(await queue.pop(), 1);
assertEquals(await queue.pop(), 2);
assertEquals(await queue.pop(), 3);

Type Parameters

T

The type of items in the queue.

Properties

readonly
locked: boolean

Returns true if the queue is currently locked.

readonly
size: number

Gets the number of items in the queue.

Methods

pop(unnamed 0?: WaitOptions): Promise<T>

Removes the next item from the queue, optionally waiting if the queue is currently empty.

push(value: T): void

Adds an item to the end of the queue and notifies any waiting consumers.