Skip to main content

interface Channel.Read<T>

A read-only Channel that can perform blocking reads. This means that a receive call will block until a message is available.

Extends: AsyncStreamable<T>

Implemented by: CrossChannel<TSend,TReceive>, Channel<T>

Type parameters

NameDefaultDescription
Tvoidthe channel message type

Properties

capacity

The maximum amount of messages the Channel can buffer. If 0, the channel is unbuffered and the communication is synchronous.

Definition

get capacity(): number;

isExhausted

Returns true if the channel is closed and there are no message in the buffer (length = 0), false otherwise.

Definition

get isExhausted(): boolean;

length

The amount of messages currently in the read buffer.

Definition

get length(): number;

Methods

asyncStream

Returns an asynchronous stream of values.

Definition

asyncStream(): AsyncStream<T>;

Overrides

AsyncStreamable.asyncStream

readable

Returns the Channel as a readonly Channel.Read instance.

Definition

readable(): Channel.Read<T>;

receive

Returns the next message sent to the Channel. Blocks if there are no messages.

Definitions

receive<RT>(options: {
      signal?: AbortSignal | undefined;
      timeoutMs?: number | undefined;
      recover: (channelError: Channel.Error) => RT;
    }): Promise<T | RT>;

receive(options?: {
      signal?: AbortSignal | undefined;
      timeoutMs?: number | undefined;
      recover?: undefined;
    }): Promise<T>;

Type parameters

NameDescription
RT

Parameters

NameTypeDescription
options{
      signal?: AbortSignal | undefined;
      timeoutMs?: number | undefined;
      recover: (channelError: Channel.Error) => RT;
    }
(optional) the options to receive a message
- signal: (optional) an abort signal to cancel receiving
- timeoutMs: (optional) amount of milliseconds to wait for received message
- recover: (optional) a function that can be supplied to recover from a channel error