@azerum/ts-csp
    Preparing search index...

    Interface ReadableChannel<T>

    Channel that can be read from. Implements AsyncIterable, hence can be used with for await loop

    interface ReadableChannel<T extends NotUndefined> {
        raceRead: () => Selectable<undefined | T>;
        read: () => Promise<undefined | T>;
        tryRead: () => undefined | T;
        waitUntilReadable: <const R>(value: R, signal?: AbortSignal) => Promise<R>;
        get closed(): boolean;
        get readableWaitsCount(): number;
        "[asyncIterator]"(): AsyncIterator<T, any, any>;
    }

    Type Parameters

    Hierarchy (View Summary)

    Implemented by

    Index

    Properties

    raceRead: () => Selectable<undefined | T>

    Like ReadableChannel.read, but can be used with select

    read: () => Promise<undefined | T>

    Reads a value from the channel. If there are no values, blocks until there is

    If channel is buffered, takes next value from the buffer. This unblocks first of blocked WritableChannel.write calls if there are any

    If channel is unbuffered, simply unblocks the first of blocked WritableChannel.write

    If the channel is closed and has no values left in the buffer, returns undefined

    Concurrent calls are allowed - each read will get own value (no two reads will get the same value). If multiple calls are blocked, they will unblock one-by-one in unspecified order

    Note: each blocked call occupies memory, and there is no limit on how many calls there can be at once. Typically, programs have a fixed or a finite number of reads, so this should not be a problem

    tryRead: () => undefined | T

    Non-blocking version of ReadableChannel.read. Unlike ReadableChannel.read, if channel has no values, returns undefined

    This means undefined is returned in two cases: (1) the channel is open but has no values, and the channel is closed and has no values. Use ReadableChannel.closed to tell those apart

    waitUntilReadable: <const R>(value: R, signal?: AbortSignal) => Promise<R>

    Blocks until the channel is "readable", meaning that it either:

    Intuitively, a channel is "readable" when the next ReadableChannel.read call on it does not block (resolves immediately)

    Type Declaration

      • <const R>(value: R, signal?: AbortSignal): Promise<R>
      • Type Parameters

        • const R

        Parameters

        • value: R

          Specify a value to return once the wait unblocks

        • Optionalsignal: AbortSignal

          Use signal to cancel the wait. This frees up memory occupied by the wait. After cancelling, the wait will throw AbortedError

        Returns Promise<R>

    Accessors

    Methods

    • Returns AsyncIterator<T, any, any>