Mux

zio.blocks.mux.Mux
See theMux companion object
trait Mux[Id, In, Out]

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.
  • capacity is 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., Int for HTTP/2 stream IDs)

In

Message type sent on streams (outbound from user code)

Out

Message type received on streams (inbound to user code)

Attributes

Companion
object
Source
Mux.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Abstract methods

def activeCount: Int

Number of currently active streams.

Number of currently active streams.

Attributes

Source
Mux.scala
def cancel(id: Id, reason: MuxError): Unit

Cancel a stream by ID with an error reason.

Cancel a stream by ID with an error reason.

Transitions: Any -> CLOSED (via RST_STREAM equivalent)

Value parameters

id

Stream identifier

reason

Error reason

Attributes

Source
Mux.scala
def closeAll(reason: MuxError): Unit

Close all active streams with an error reason.

Close all active streams with an error reason.

Value parameters

reason

Error reason

Attributes

Source
Mux.scala
def get(id: Id): Option[MuxStream[Id, In, Out]]

Get an existing stream by ID.

Get an existing stream by ID.

Value parameters

id

Stream identifier

Attributes

Returns

Some(stream) if open, None otherwise

Source
Mux.scala
def open(id: Id): MuxStream[Id, In, Out] | MuxError

Open a new stream with the given ID.

Open a new stream with the given ID.

Transitions: IDLE -> OPEN

Value parameters

id

Stream identifier

Attributes

Returns

A new MuxStream or an error (e.g., capacity exceeded, mux closed)

Source
Mux.scala