Overview
Channels provide WebSocket-backed streaming communication between workers. They enable efficient transfer of large binary data and real-time messaging without going through the function invocation protocol.Creating Channels
create_channel
Create a bidirectional streaming channel.Option<usize>
Internal buffer size for the channel (default determined by engine)
Result<Channel, IIIError>
A channel with writer, reader, and their serializable references
Writing to Channels
ChannelWriter
The writer side of a channel supports writing binary data and text messages.write
Write binary data to the channel.&[u8]
required
Binary data to write to the channel
Data larger than 64KB is automatically chunked into multiple WebSocket frames.
send_message
Send a text message to the channel.&str
required
Text message to send
close
Close the writer side of the channel.Reading from Channels
ChannelReader
The reader side of a channel supports reading binary data and receiving text messages.next_binary
Read the next binary chunk from the channel.Result<Option<Vec<u8>>, IIIError>
The next binary chunk, or
None when the channel is closedText messages are not returned by
next_binary(). Register a callback with on_message() to handle text messages.read_all
Read the entire stream into a single buffer.Result<Vec<u8>, IIIError>
All binary data from the channel concatenated into a single buffer
on_message
Register a callback for text messages.F
required
Callback invoked for each text message received
close
Close the reader side of the channel.Passing Channels to Functions
Channel references are serializable and can be passed as function arguments:Receiving Channel References
In a function handler, extract channel references and create reader/writer instances:Channel Utilities
is_channel_ref
Check if a JSON value is a channel reference.extract_channel_refs
Extract all channel references from a JSON value.&Value
required
JSON value to search for channel references
Vec<(String, StreamChannelRef)>
List of (field path, channel reference) tuples
Types
Channel
A bidirectional streaming channel.StreamChannelRef
Serializable reference to a channel endpoint.ChannelDirection
Direction of a channel reference.Complete Example
Here’s a complete example showing data streaming between two workers:See Also
- Functions API - Pass channels to functions
- Streaming API - Stream updates and atomic operations
- Invocation API - Call functions with channel arguments