Skip to main content
Module

x/streamtools/pop.ts>pop

🦕 This is a Deno module that provides utilities for handling Streams API.
Latest
function pop
import { pop } from "https://deno.land/x/streamtools@v1.0.0/pop.ts";

Reads the next chunk from a readable stream.

import { pop } from "./pop.ts";

const reader = new ReadableStream<number>({
  start(controller) {
    controller.enqueue(1);
    controller.enqueue(2);
    controller.enqueue(3);
    controller.close();
  },
});

console.log(await pop(reader)); // 1
console.log(await pop(reader)); // 2
console.log(await pop(reader)); // 3
console.log(await pop(reader)); // null

Type Parameters

T

The type of the chunk to read.

Parameters

stream: ReadableStream<T>

The stream to read from.

Returns

Promise<T | null>

A promise that resolves with the next chunk from the stream or null if the stream is closed.