Skip to main content

Documentation Index

Fetch the complete documentation index at: https://motiadev-feat-improve-erros-if-trigger-does-not-exists.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

Goal

Stream a large or binary payload from one function to another without putting the data itself in a JSON function payload. Use a normal function invocation when the payload is small JSON and can be handled as one request. Use a channel when the payload is large, binary, or naturally stream-shaped. Good fits for channels:
  • File uploads and downloads.
  • Images, audio, video, PDFs, and datasets.
  • Progress updates during long-running work.
  • Producer and consumer pipelines where the data should move as a stream.
For the underlying model, see Channels architecture.

Steps

1. Create a channel

A channel has two local stream objects and two serializable refs:
  • writer: local writable stream.
  • reader: local readable stream.
  • writerRef: serializable token for the writer end.
  • readerRef: serializable token for the reader end.
const channel = await iii.createChannel();

// channel.writer
// channel.reader
// channel.writerRef
// channel.readerRef

2. Write to the channel

Write the stream payload to the local writer and close it when you are done.
const channel = await iii.createChannel();

channel.writer.stream.end(Buffer.from("file contents"));

3. Pass the reader ref to another function

Pass the readerRef / reader_ref as part of a normal function invocation. The receiving function uses that ref to read from the channel.
const result = await iii.trigger({
  function_id: "files::process",
  payload: {
    filename: "report.csv",
    reader: channel.readerRef,
  },
});

4. Read from the channel

Node and Python deserialize channel refs into live channel objects before your handler runs. Rust receives the ref in JSON and reconstructs the reader with ChannelReader::new(...).
import type { ChannelReader } from "iii-sdk";

worker.registerFunction("files::process", async (input: { reader: ChannelReader }) => {
  let bytes = 0;

  for await (const chunk of input.reader.stream) {
    bytes += Buffer.isBuffer(chunk) ? chunk.length : Buffer.byteLength(chunk);
  }

  return { bytes };
});

Result

The caller passes only a small ref through trigger(). The stream payload travels over the channel, and the receiving function reads it incrementally.