Skip to main content

Type parameters

Name
T

Properties#

fail#

• fail: (error: Error) => void

See ChannelSender.fail.

Type declaration:#

â–¸ (error: Error): void

Behaves exactly like close, except throws an error in the consumer once the channel is flushed.

Parameters:#

NameType
errorError

Returns: void

Defined in: channels/channel_interfaces.ts:37

Defined in: channels/channel_interfaces.ts:92


isDone#

• isDone: boolean

Set to true just before the last value is returned from the channel, if the channel was closed. This is useful for determining if the value yielded while iterating a channel is the last value the channel will ever send.

Defined in: channels/channel_interfaces.ts:46

Methods#

[Symbol.asyncIterator]#

â–¸ [Symbol.asyncIterator](): AsyncIterator<ChannelReceiveResult<T>, any, undefined>

Consumes the channel receiver (the other read methods can't be used any more) and provides an async iterator over the channel. This iterator returns once the channel is closed without error (it throws if the channel is failed).

try {
// Iterate through each value one at a time, asynchronously
for await (const value of receiver) {
// Do something with `value` here.
}
// Once execution gets to here, the channel has been closed.
} catch (e) {
// You can wrap consuming of the channel in a try-catch to handle `fail`
// being called on the channel.
}

Returns: AsyncIterator<ChannelReceiveResult<T>, any, undefined>

Defined in: channels/channel_interfaces.ts:89


awaitPeekFirst#

â–¸ awaitPeekFirst(): Promise<null | ChannelReceiveResult<T>>

Awaits the first message in the stream and returns it without removing it from the stream. This is useful for peaking at the first message to switch on exchange type or something similar. None is returns if the stream was closed before anything was sent over it.

Returns: Promise<null | ChannelReceiveResult<T>>

Defined in: channels/channel_interfaces.ts:67


opened#

â–¸ opened(): Promise<void>

Returns a promise that resolves once the channel has been opened.

Returns: Promise<void>

Defined in: channels/channel_interfaces.ts:49


tryReceiveNow#

â–¸ tryReceiveNow(): null | ChannelReceiveResult<T>

Attempts to receive a single item from the channel immediately, returning None if there is no waiting data in the buffer. Important note: this will remove a pending value from the buffer immediately, meaning if the receiver has already been consumed, but is still busy processing a previous value, this call can 'steal' a value from the consume. It's unlikely you want to mix consume and tryReceiveNow together.

Returns: null | ChannelReceiveResult<T>

Defined in: channels/channel_interfaces.ts:59