Prelude API
    Preparing search index...

    Class Channel<T>

    Type Parameters

    • T

    Implements

    • AsyncIterableIterator<T>
    Index
    • get done(): boolean

      Returns boolean

      true if channels has been closed and there are no pending writes.

    • get doneWriting(): boolean

      Returns boolean

      true if channel has been closed for writing.

    • get error(): unknown

      Returns unknown

      error passed to fail, undefined if channel has not failed.

    • get failed(): boolean

      Returns boolean

      true if channel has been failed through fail.

    • get pendingReads(): number

      Returns number

      number of pending reads.

    • get pendingWrites(): number

      Returns number

      number of pending writes.

    • Closes channel for both reading and writing.

      Idempotent: a channel that is already closed for writing (for example a producer that finished before the consumer stopped iterating) is drained without throwing.

      Parameters

      • Optionalerr: unknown

      Returns void

      closeWriting for closing channel for writing only.

    • Closes writing only.

      Writes beyond capacity are settled with optional err.

      If there are no pending writes channel is effectively done - closed for reading and writing.

      Parameters

      • Optionalerr: unknown

      Returns void

      close for closing channel for reading and writing.

    • Parameters

      • result: IteratorResult<T>

      Returns void

    • Returns T[]

      all values that was possible to read immediatelly, aka all pending writes.

    • Fails the channel: closes it for reading and writing, rejects pending writes with err (even when err is falsy) and rejects pending and subsequent reads with err.

      Unlike close, which completes readers normally, this propagates a producer error to consumers (next(), read(), maybeRead() and for await reject with err).

      No-op if the channel is already closed for writing.

      Parameters

      • err: unknown

      Returns void

    • Reads the next value, returning undefined after channel completion.

      When T includes undefined, a queued undefined value and channel completion have the same return value. Use next() and inspect done when that distinction matters.

      Parameters

      • __namedParameters: { signal?: AbortSignal } = {}

      Returns Promise<T | undefined>

    • Like write, resolving with false instead of rejecting (including on abort).

      Parameters

      • value: T
      • options: { signal?: AbortSignal } = {}

      Returns Promise<boolean>

    • Returns Promise<IteratorResult<T, any>>

    • Registers callback to be called when channel has done writing. Callback is called immediatelly if channel is already closed for writing.

      Parameters

      Returns Undo

      undo function that unregisters callback.

    • Parameters

      • __namedParameters: { signal?: AbortSignal } = {}

      Returns Promise<T>

      if channel is closed.

    • Type Parameters

      • R

      Parameters

      • perform: (result: IteratorResult<T>) => IteratorResult<R>

      Returns ReadAttempt<T, R>

    • Parameters

      • Optionalvalue: any

      Returns Promise<{ done: boolean; value: any }>

    • Parameters

      • Optionalerr: any

      Returns Promise<{ done: boolean; value: any }>

    • Writes value; resolves once a reader took it or it was buffered.

      Aborting signal while the write is still blocked withdraws it — the value is never delivered — and rejects with signal.reason; a write that was already accepted is unaffected. A signal that is already aborted rejects without touching the channel.

      Parameters

      • value: T
      • __namedParameters: { signal?: AbortSignal } = {}

      Returns Promise<void>

    • Parameters

      • value: T
      • options: { signal?: AbortSignal } = {}

      Returns void