worker.trigger(...) call.
For the underlying model (how channels are addressed, multiplexed, and torn down), see Channels
architecture.
Payload size
As of SDK version 0.24.5, the Rust, Node, Python, and Go SDKs reject outbound JSON envelopes larger than 16 MiB locally withpayload_too_large. The size is measured in bytes across the complete
serialized UTF-8 JSON envelope, not just the function payload value. The browser SDK in version
0.24.5 does not check outbound message size before sending. For browser payloads larger than
16 MiB, use a channel.
Messages at or below 16 MiB are sent as a single WebSocket text frame. Channels stream payload
bytes separately from the JSON function envelope, making them suitable for larger data and
continuous transfers.
Using channels
A channel is created by one worker and has two local stream ends:writer and reader; plus two
serializable refs (writerRef / readerRef) that can be handed to another function. The
subsections below cover the local-end API: creating a channel, writing bytes into its writer, and
reading bytes from its reader.
Create a channel
worker.createChannel() returns a channel with two local stream objects and two serializable refs:
writer and reader are the local stream ends, and writerRef / readerRef are the tokens you
pass to another function so it can read or write the other end.
- Node / TypeScript
- Python
- Rust
Write to a channel
Write the payload to the localwriter and close it when finished. The bytes flow through the
engine to whichever worker holds the matching reader.
- Node / TypeScript
- Python
- Rust
Read from a channel
Read the localreader until the other end closes. The bytes arrive in the order they were written
by whichever worker holds the matching writer.
- Node / TypeScript
- Python
- Rust
Using channels across functions
A channel only becomes useful once both ends are owned by different code paths. Typically one function that holds the localwriter / reader and another that receives the matching ref in its
payload. The two subsections below cover that handoff: first how to send a ref alongside a normal
trigger call, then how the receiving function turns it back into a live stream to read or write.
Pass a channel ref to another function
Pass thereaderRef (or writerRef) as part of a normal function invocation. The receiving
function uses the ref to read from (or write to) the channel.
- Node / TypeScript
- Python
- Rust
ChannelReader / ChannelWriter
objects before the handler runs, so the ref arrives ready to iterate or write to. Rust receives the
ref in JSON and reconstructs the reader or writer explicitly with ChannelReader::new(...) or
ChannelWriter::new(...).
Read from a channel ref
- Node / TypeScript
- Python
- Rust
Write to a channel ref
- Node / TypeScript
- Python
- Rust