Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/iii-hq/sdk/llms.txt

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

Channels enable streaming data transfer between workers in a distributed III application. They provide bidirectional communication with reader and writer endpoints.

Channel

A streaming channel pair created by createChannel(), containing both local handles and serializable references.
type Channel = {
  writer: ChannelWriter
  reader: ChannelReader
  writerRef: StreamChannelRef
  readerRef: StreamChannelRef
}

Fields

writer
ChannelWriter
required
Local writer for sending data through the channel.
reader
ChannelReader
required
Local reader for receiving data from the channel.
writerRef
StreamChannelRef
required
Serializable reference to the writer endpoint. Pass this to other workers to allow them to write to this channel.
readerRef
StreamChannelRef
required
Serializable reference to the reader endpoint. Pass this to other workers to allow them to read from this channel.

StreamChannelRef

A serializable reference to a channel endpoint that can be passed in function invocation data.
type StreamChannelRef = {
  channel_id: string
  access_key: string
  direction: 'read' | 'write'
}

Fields

channel_id
string
required
Unique identifier for the channel.
access_key
string
required
Secret access key for authenticating to the channel endpoint.
direction
'read' | 'write'
required
Whether this reference is for reading from or writing to the channel.

ChannelWriter

Writer endpoint for sending data through a channel.
class ChannelWriter {
  readonly stream: Writable
  sendMessage(msg: string): void
  close(): void
}

Properties

stream
WritableStream
required
Node.js Writable stream interface for sending binary data.

Methods

write
function
Write binary data to the channel. Data is automatically chunked into frames.
sendMessage
function
Send a text message through the channel (separate from binary data stream).
close
function
Close the writer endpoint and signal completion to the reader.

ChannelReader

Reader endpoint for receiving data from a channel.
class ChannelReader {
  readonly stream: Readable
  onMessage(callback: (msg: string) => void): void
}

Properties

stream
ReadableStream
required
Node.js Readable stream interface for receiving binary data.

Methods

onMessage
function
Register a callback to receive text messages (separate from binary data stream).
next_binary
function
Read the next binary chunk from the channel. Returns None when stream is closed.
read_all
function
Read the entire stream into a single buffer.
close
function
Close the reader endpoint.

Usage Examples

Basic Channel Communication

// Worker A: Create and send channel
const channel = await iii.createChannel()

// Pass writer ref to another worker
await iii.trigger('worker-b::process', {
  input: 'some data',
  output_channel: channel.writerRef
})

// Read results from the channel
for await (const chunk of channel.reader.stream) {
  console.log('Received:', chunk.toString())
}

Receiving Channel Reference

// Worker B: Receive channel ref and write to it
type ProcessInput = {
  input: string
  output_channel: StreamChannelRef
}

iii.registerFunction(
  { id: 'worker-b::process' },
  async (data: ProcessInput) => {
    const writer = new ChannelWriter(engineUrl, data.output_channel)
    
    // Write results to the channel
    writer.stream.write('Processing...\n')
    const result = await processData(data.input)
    writer.stream.write(`Result: ${result}\n`)
    
    writer.close()
    return { success: true }
  }
)

Streaming Large Files

import { createReadStream } from 'fs'
import { pipeline } from 'stream/promises'

const channel = await iii.createChannel()

// Stream file to another worker
await iii.trigger('worker-b::save-file', {
  filename: 'large-file.dat',
  data_channel: channel.readerRef
})

// Pipe file data through the channel
const fileStream = createReadStream('large-file.dat')
await pipeline(fileStream, channel.writer.stream)

Configuration

Buffer Size

When creating a channel, you can optionally specify a buffer size:
const channel = await iii.createChannel(128) // 128 message buffer
Default: 64 messages The buffer size determines how many messages can be queued in the channel before backpressure is applied to the writer.

Build docs developers (and LLMs) love