Channel
Source: lib/channel.x
Guide: Channels
Var transport and explicit storage handoff.
Primary API
| Function | Summary |
|---|---|
Channel.cleanup | Ends the owned lifetime when a managed local leaves its block. |
Channel.close | Ends sends and wakes waiters; accepted messages remain available to drain. |
Channel.free | Closes the Channel and destroys its storage scope. |
Channel.iter | Initializes a borrowed iterator that blocks for each received message. |
Channel.new | Creates a Channel constrained to an exact Var tag, with capacity zero for rendezvous, a nonnegative integer for bounded buffering, or <unbounded>. |
Channel.receive | Receives one accepted Var. |
Channel.scope | Returns the Channel’s own storage scope. |
Channel.send | Sends non-void representation bits without changing referenced storage ownership. |
Channel.send_owned | Hands off an exclusively owned payload. |
Channel.var | Boxes the borrowed Channel handle without changing its lifetime. |
Var.channel | Reads a Channel handle with its exact tag. |
Channel
Channel.cleanup
void Channel.cleanup(Channel value)
Ends the owned lifetime when a managed local leaves its block.
Source: lib/channel.x
Channel.close
void Channel.close(Channel channel)
Ends sends and wakes waiters; accepted messages remain available to drain. Repeated close is harmless, and NULL does nothing. Closing does not stop Thread users, free payloads, or acknowledge completion of a borrow.
Source: lib/channel.x
Channel.free
void Channel.free(Channel channel)
Closes the Channel and destroys its storage scope. Every user and
waiter must already have finished. Cleanup destroys undelivered owned
payload subtrees outside the queue mutex and leaves borrowed payload
storage alone. NULL does nothing. Destroying the owner runs the same
finalizer to release native queue nodes and resources.
Source: lib/channel.x
Channel.iter
Iter Channel.iter(Channel c, Iter dest)
Initializes a borrowed iterator that blocks for each received message. Normal close and draining end iteration; cooperative stop raises instead. The Channel must outlive traversal.
Source: lib/channel.x
Channel.new
Channel Channel.new(Var type, Var capacity)
Creates a Channel constrained to an exact Var tag, with capacity zero
for rendezvous, a nonnegative integer for bounded buffering, or
<unbounded>. The <var> tag permits every non-void Var without
conversion. Short forms are new(), new(capacity), and new(tag); omitted
capacity means rendezvous. Queuing does not intern or export message
contents.
Raises: <bad-arg> for an unknown tag or invalid capacity, <alloc-fail>
for storage, or <io-fail> for native mutex or condition initialization.
Source: lib/channel.x
Channel.receive
Var Channel.receive(Channel channel)
Receives one accepted Var. Ordinary payloads stay borrowed. Owned Map and Array storage moves into the receiver’s private active Scope, releasing the empty transport Scope. Prepared custom subtrees join that private owner. Receiver failure cleanup reclaims received storage normally. Returns void only after close and draining; null remains ordinary data. A committed delivery succeeds despite a later stop request.
Raises: <bad-arg> for NULL, <alloc-fail> preparing receiver storage, or
<bad-state> for cooperative stop.
Source: lib/channel.x
Channel.scope
Scope Channel.scope(Channel channel)
Returns the Channel’s own storage scope. Owned queued payloads stay detached; ordinary messages remain borrowed. This scope is not a shared adoption destination for concurrent senders.
Raises: <bad-arg> for NULL.
Source: lib/channel.x
Channel.send
void Channel.send(Channel c, Var value)
Sends non-void representation bits without changing referenced storage ownership. Waits for queue capacity or a rendezvous match. Acceptance commits under synchronization; later stop cannot retract that send.
Raises: <bad-arg> for NULL, <void-op> for void, <bad-types> for a tag
mismatch, <bad-state> for closure or cooperative stop, or <alloc-fail>
for native buffered queue storage. Failure dispatch holds no queue lock.
Source: lib/channel.x
Channel.send_owned
void Channel.send_owned(Channel c, Var value)
Hands off an exclusively owned payload. Ordinary Map and Array records, buffers, and existing owned contents move into a transport Scope created only for this send. Custom or typed roots require a preexisting exclusive inactive subtree containing their full physical storage. The detached scope is recovered through the root’s allocation header while queued. Failed sends restore the container allocation owner and contents parent, or the custom subtree parent, before raising. Acceptance transfers access and cleanup responsibility. This cannot disarm initializer auto or defer; the caller must not leave such cleanup armed after acceptance. A subtree must not be handed off twice. Canonical Strings/Lists and independent referenced objects are not implicitly adopted. Pointer provenance and ownership graphs remain caller responsibilities.
Raises: the send causes, or <bad-arg> for a null/nonpointer payload.
Source: lib/channel.x
Channel.var
Var Channel.var(Channel channel)
Boxes the borrowed Channel handle without changing its lifetime.
Source: lib/channel.x
Var
Var.channel
Channel Var.channel(Var value)
Reads a Channel handle with its exact tag. Ownership is unchanged.
Raises: <bad-types> for another tag.
Source: lib/channel.x
Public types
| Type | Kind | Summary |
|---|---|---|
Channel | struct | A synchronized non-void Var stream with explicitly managed payload lifetimes. |
Channel
typedef struct Channel *Channel
A synchronized non-void Var stream with explicitly managed payload lifetimes. Ordinary send copies bits without ownership changes; send_owned explicitly hands off a detached, exclusively owned storage subtree. Close ends sends and lets accepted values drain. Every user and waiter must finish before the Channel’s storage scope is destroyed.
Source: lib/channel.x
Design notes
Each queue has its own mutex. To publish a stop request while a Channel
operation is registered, the stop operation takes that mutex. This orders
the stop request with message commitment. Allocation,
Error dispatch, and payload destruction happen outside the lock.