A multiplexer that manages multiple independent streams over a shared transport.
Each stream is identified by a unique Id and has independent inbound/outbound message queues. The multiplexer enforces a maximum number of concurrent streams (capacity). Attempting to open a stream beyond that limit returns MuxError.CapacityExceeded.
'''Invariants:'''
- Stream IDs must be unique among active streams; opening a duplicate returns MuxError.ProtocolError.
capacityis fixed at construction and never changes.- After closeAll, no new streams can be opened (MuxError.MuxClosed is returned) and all previously active streams transition to CLOSED with the supplied error enqueued for any pending receive.
'''Thread safety:''' open, get, cancel, closeAll, and activeCount are safe to call from multiple threads concurrently. Per-stream operations on MuxStream: send and offerInbound are multi-thread safe. receive and takeOutbound must each be called from a single consumer thread at a time (single-consumer contract of the underlying ring buffer).
Type parameters
- Id
-
Stream identifier type (e.g.,
Intfor HTTP/2 stream IDs) - In
-
Message type sent on streams (outbound from user code)
- Out
-
Message type received on streams (inbound to user code)