MuxStream

zio.blocks.mux.MuxStream
trait MuxStream[Id, In, Out]

Individual stream within a Mux.

Encapsulates the state machine for a single stream (IDLE, OPEN, HALF_CLOSED_LOCAL, HALF_CLOSED_REMOTE, CLOSED). Provides send/receive operations and state queries.

This stream has two separate message queues:

  • '''Outbound queue''': messages sent by user code via send(), drained by the mux/protocol via takeOutbound()
  • '''Inbound queue''': messages delivered by the mux/protocol via offerInbound(), read by user code via receive()

Type parameters

Id

Stream identifier type

In

Message type sent on this stream

Out

Message type received on this stream

Attributes

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

Members list

Value members

Abstract methods

def close(): Unit

Fully close this stream immediately.

Fully close this stream immediately.

Transitions the stream to CLOSED state and enqueues a terminal error. After this call:

Attributes

Source
Mux.scala
def halfClose(): Unit

Signal that this side is done sending (END_STREAM equivalent).

Signal that this side is done sending (END_STREAM equivalent).

Transitions: OPEN -> HALF_CLOSED_LOCAL or HALF_CLOSED_REMOTE -> CLOSED

After this, send() will fail. receive() still works.

Attributes

Source
Mux.scala
def id: Id

Stream identifier.

Stream identifier.

Attributes

Source
Mux.scala
def isClosed: Boolean

Check if stream is fully closed.

Check if stream is fully closed.

Attributes

Returns

true if state is CLOSED

Source
Mux.scala
def isHalfClosed: Boolean

Check if stream is half-closed (one side done).

Check if stream is half-closed (one side done).

Attributes

Returns

true if state is HALF_CLOSED_LOCAL or HALF_CLOSED_REMOTE

Source
Mux.scala
def offerInbound(msg: Out): Unit | MuxError

Deliver a message to this stream's inbound queue.

Deliver a message to this stream's inbound queue.

Called by the mux/protocol layer to deliver messages TO this stream.

Value parameters

msg

Message to deliver

Attributes

Returns

Success or an error if the stream is closed

Source
Mux.scala
def receive(): Option[Out] | MuxError

Receive a message from the inbound queue.

Receive a message from the inbound queue.

Returns the next available inbound message, or None if no message is available yet. Returns an error if the stream is closed.

Attributes

Returns

Some(msg) if a message is available, None if no message yet, or an error if closed

Source
Mux.scala
def send(msg: In): Unit | MuxError

Send a message on this stream.

Send a message on this stream.

Places the message into the outbound queue for the mux/protocol to drain. Fails if stream is closed or in HALF_CLOSED_LOCAL state.

Value parameters

msg

Message to send

Attributes

Returns

Success or an error

Source
Mux.scala
def signalRemoteClose(): Unit

Signal that the remote side is done sending.

Signal that the remote side is done sending.

Transitions: OPEN -> HALF_CLOSED_REMOTE or HALF_CLOSED_LOCAL -> CLOSED

Called by the mux/protocol layer when the peer signals END_STREAM.

Attributes

Source
Mux.scala
def takeOutbound(): Option[In] | MuxError

Take the next message from the outbound queue.

Take the next message from the outbound queue.

Called by the mux/protocol layer to drain messages FROM this stream. Returns None if no outbound message is available.

Attributes

Returns

Some(msg) if a message is available, None if empty, or an error if closed

Source
Mux.scala