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

    Interface WritableChannel<T>

    Channel that can be written into

    interface WritableChannel<T extends NotUndefined> {
        close: () => void;
        raceWrite: (value: T) => Selectable<void>;
        tryWrite: (value: T) => boolean;
        waitUntilWritable: <const R>(value: R, signal?: AbortSignal) => Promise<R>;
        write: (value: T) => Promise<void>;
        get closed(): boolean;
        get writableWaitsCount(): number;
    }

    Type Parameters

    Hierarchy (View Summary)

    Implemented by

    Index

    Properties

    close: () => void

    Closes the channel. Closed channels cannot be written to. They can still be read from if there are values left in the buffer

    More precisely, after close:

    Unlike in Go, this method is idempotent

    raceWrite: (value: T) => Selectable<void>

    Like WritableChannel.write, but can be used with select

    tryWrite: (value: T) => boolean

    Non-blocking version of WritableChannel.write. Returns true is the value was written into the channel. Returns false when WritableChannel.write would block. Throws if the channel is closed

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

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

    Intuitively, a channel is "writable" when the next WritableChannel.write call on it does not block (resolves or rejects 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>

    write: (value: T) => Promise<void>

    Writes value to the channel. If there is no free space in the channel, blocks until there is. This gives backpressure: if writer is faster than reader, the channel buffer will eventually fill up and the writer will start to block

    If channel is buffered, tries to write value in the buffer, and blocks if the buffer is full. If channel is unbuffered, waits for ReadableChannel.read call (resolved immediately if there is a blocked ReadableChannel.read call already)

    If the channel was closed before the call, or became closed while the call was blocked, throws CannotWriteIntoClosedChannel

    Order of values is guaranteed for sequential writes: after await ch.write(1); await ch.write(2), 1 is guaranteed to be read before 2. Order is not guaranteed for concurrent writes: after await Promise.race([ch.write(1), ch.write(2)]), 1 and 2 can appear in any order when reading

    Note: in current implementation, order of values is the same as order of calls to write(), so example above will always give 1, 2. This will change in future if worker_threads support will be implemented. It is not advisable to rely on this

    Accessors