Skip to main content
Module

x/async/mod.ts>Stack

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

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

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

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

Type Parameters

T

The type of items in the stack.

Properties

readonly
locked: boolean

Returns true if the stack 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 stack, optionally waiting if the stack is currently empty.

push(value: T): void

Adds an item to the top of the stack and notifies any waiting consumers.