interface CrossChannel<TSend,TReceive>
A CrossChannel is a channel of which the send and receive modules are not internally connected. This means that the send and receive message types can also differ. A normal Channel can receive its own message, but a CrossChannel cannot, and so they are usually created in pairs to perform bidirectional communication with some other entity.
Companion namespace: CrossChannel
Extends: Channel.Write<T>
, Channel.Read<T>
Type parameters
Name | Default | Description |
---|---|---|
TSend | void | the send message type |
TReceive | TSend | the receive message type |
Properties
capacity
The maximum amount of messages the Channel can buffer. If 0, the channel is unbuffered and the communication is synchronous.
capacity
isClosed
Returns true if the Channel is closed.
isClosed
isExhausted
Returns true if the channel is closed and there are no message in the buffer (length = 0), false otherwise.
isExhausted
length
The amount of messages currently in the read buffer.
length
Methods
asyncStream
Returns an asynchronous stream of values.
asyncStream
close
Closes the channel. After a close, further send actions will throw.
close
readable
Returns the Channel as a readonly Channel.Read instance.
readable
receive
Returns the next message sent to the Channel. Blocks if there are no messages.
receive
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
Name | Description |
---|---|
RT |
Parameters
Name | Type | Description |
---|---|---|
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 |
Overrides
send
Send the given value
message to the Channel. Blocks if the Channel is already at maximum capacity.
send
value
message to the Channel. Blocks if the Channel is already at maximum capacity.Definitions
send(value: T, options: {
signal?: AbortSignal
|
undefined;
timeoutMs?: number
|
undefined;
catchChannelErrors?: false
|
undefined;
}): Promise<void>;
send(value: T, options?: {
signal?: AbortSignal
|
undefined;
timeoutMs?: number
|
undefined;
catchChannelErrors: boolean;
}): Promise<undefined
|
Channel.Error
>;
Parameters
Name | Type | Description |
---|---|---|
value | T | the message to send to the channel |
options | { signal?: AbortSignal | undefined; timeoutMs?: number | undefined; catchChannelErrors?: false | undefined; } | (optional) the message send options - signal: (optional) an abort signal to cancel sending - timeoutMs: (optional) amount of milliseconds to wait for being able to send message - recover: (optional) a function that can be supplied to recover from a channel error |
Overrides
sendAll
Sequentially send all the values in the given source
to the channel. Blocks until all the values are sent.
sendAll
source
to the channel. Blocks until all the values are sent.Definitions
sendAll(source:
AsyncStreamSource
<T>, options: {
signal?: AbortSignal
|
undefined;
timeoutMs?: number
|
undefined;
catchChannelErrors?: false
|
undefined;
}): Promise<void>;
sendAll(source:
AsyncStreamSource
<T>, options?: {
signal?: AbortSignal
|
undefined;
timeoutMs?: number
|
undefined;
catchChannelErrors: boolean;
}): Promise<undefined
|
Channel.Error
>;
Parameters
Name | Type | Description |
---|---|---|
source | AsyncStreamSource <T> | a stream source containing the values to send |
options | { signal?: AbortSignal | undefined; timeoutMs?: number | undefined; catchChannelErrors?: false | undefined; } | the message send options - signal: (optional) an abort signal to cancel sending - timeoutMs: (optional) amount of milliseconds to wait for being able to send message, for each separate message in the source - recover: (optional) a function that can be supplied to recover from a channel error |
Overrides
writable
Returns the Channel as a write-only Channel.Write instance.
writable