Std\Channel
Std\Channel — bounded MPMC channels with type-safe sender/receiver split.
channel n returns (Linear (Sender a), Linear (Receiver a)). The
linearity checker enforces that each side is unwrapped from Linear
exactly once via pattern match. After unwrapping, a Sender a can only
send and a Receiver a can only recv / tryRecv, enforcing the
producer/consumer split at the type level.
Sender and Receiver endpoints implement both Send and Shareable because
the runtime channel is synchronized; each transmitted payload must
independently implement Send.
See docs/api/Channel.md for the full API.
Sender
Section titled “Sender”type Sender a = Sender Channel
Send-only handle wrapping a Channel.
Receiver
Section titled “Receiver”type Receiver a = Receiver Channel
Receive-only handle wrapping a Channel.
Functions
Section titled “Functions”channel : Int -> (Linear (Sender value), Linear (Receiver value))
Section titled “channel : Int -> (Linear (Sender value), Linear (Receiver value))”Compiler-backed constructor. Codegen supplies a hidden payload descriptor
after inference has made value concrete.
send : Sender value -> value -> Unit
Section titled “send : Sender value -> value -> Unit”Create a bounded channel with the given buffer capacity. Returns a tuple
of Linear-wrapped sender and receiver handles. The linearity checker
requires both wrappers to be unwrapped before scope exit:
let (sl, rl) = channel 16 incase sl of Linear sender ->case rl of Linear receiver ->... -- use sender / receiver freelyend endSend a value through a sender. Blocks if the buffer is full.
recv : Receiver value -> Option value
Section titled “recv : Receiver value -> Option value”Receive a value. Blocks if the buffer is empty. Returns Some v for a
delivered value or None once the channel is closed and drained.
tryRecv : Receiver value -> Option value
Section titled “tryRecv : Receiver value -> Option value”Non-blocking receive — returns immediately even if empty.
close : Sender value -> Unit
Section titled “close : Sender value -> Unit”Close the sender side. Wakes all blocked sends and recvs.
isClosed : Sender value -> Bool
Section titled “isClosed : Sender value -> Bool”Returns true if the channel has been closed.
length : Sender value -> Int
Section titled “length : Sender value -> Int”Current number of buffered elements.
capacity : Sender value -> Int
Section titled “capacity : Sender value -> Int”Maximum buffer size (set at creation).