UNPKG

ciorent

Version:

A lightweight, low-overhead concurrency library

28 lines (27 loc) 701 B
/** * @module Streams */ import type { PromiseFn, UnboundedQueue } from "./queue.js"; /** * Describe a stream */ export type Stream<T extends {} = {}> = [...UnboundedQueue<T | ((val?: T) => void)>, callback: PromiseFn<T>, queueing: boolean]; /** * Create a stream */ export declare const init: <T extends {} = {}>() => Stream<T>; /** * Write a value to the stream * @param s * @param v */ export declare const write: <T extends {} = {}>(s: Stream<T>, v: T) => void; /** * Read a value from the stream * @param s */ export declare const read: <T extends {} = {}>(s: Stream<T>) => Promise<T | undefined>; /** * Release all pending read with undefined */ export declare const flush: (s: Stream) => void;