MuxSeam

class MuxSeam(delegate: Seam, scope: CoroutineScope)

N-way multiplexer over a Seam.

Produces independent Seam views — one per channel tag — that share a single upstream collection of delegate's Seam.incoming. This satisfies the kuilt contract that Seam.incoming is single-collection: only MuxSeam ever collects from delegate; each channel view subscribes to the internally-shared flow.

Framing

Every outbound frame is prefixed with a 1-byte channel tag. Every inbound frame is filtered by its first byte and delivered to the matching channel view with the tag byte stripped. Frames with no matching channel are silently discarded.

Late-subscriber semantics

The shared upstream is started with replay = 0. Frames emitted before a channel view begins collecting are not replayed — this is best-effort delivery, suitable for Quilter (which heals gaps via FullState + resend) but not suitable for raw at-least-once consumers.

Channel identity

channel is idempotent: calling it twice with the same tag returns the same Seam instance. Thread-safe: concurrent channel calls are serialised by an internal reentrant lock so the backing map is never raced.

Per-channel close

ChannelView.close stops delivery to that view only — its Seam.incoming completes and further Seam.broadcast/Seam.sendTo calls become no-ops. The base Seam remains live for all other channel views. The base closes only when the owner calls closeBase (or closes the delegate directly). This deliberate owner-driven design avoids fragile last-channel reference-counting and keeps lifecycle ownership clear: the entity that opened the delegate is the entity that closes it.

Parameters

delegate

the underlying Seam whose Seam.incoming this class owns.

scope

a CoroutineScope for the shared upstream collector and per-view pipes.

Constructors

Link copied to clipboard
constructor(delegate: Seam, scope: CoroutineScope)

Functions

Link copied to clipboard
fun channel(tag: Byte): Seam

Returns a Seam view carrying only frames tagged with tag.

Link copied to clipboard
suspend fun closeBase(reason: CloseReason = CloseReason.Normal)

Closes the underlying delegate.