macula_stream (macula v4.2.7)
View SourceMacula streaming RPC — single-stream state machine.
Owns one streaming RPC's state. Each call_stream, open_stream, or server-side handler invocation gets its own macula_stream gen_server. The state machine itself is carrier-agnostic; the peer shape ({local, _} or {remote_via_link, _, _}) decides how chunks reach the wire.
Two carriers route through forward_to_peer/2:
{local, Pid}— in-process pairing for unit tests andmacula_stream_localdispatch.{remote_via_link, Link, Sid}— V2 wire format viamacula_station_link(CBORmacula_frame:stream_*frames over a peering connection).
Renamed from macula_stream_v1 in 3.17.0; the V1 mesh_client carrier ({remote, _, _}) was retired alongside the rest of the V1 surface in the same release. The module now spans the LOCAL carrier and the V2 station_link carrier only.
Summary
Functions
Abort the stream with a STREAM_ERROR frame. Both sides close; any pending recv/await_reply waiters receive {error, {Code, Message}}.
Attach a V2 macula_station_link peer to this stream. The station_link carries deliveries as V2 macula_frame:stream_* frames over its peering connection (one per pool seed); inbound STREAM_* frames are decoded by the link and forwarded into this stream via the deliver_chunk / end / error / reply casts below.
Wait for the terminal reply (client-stream / bidi).
Close both sides. Idempotent.
Half-close the write side. Recv side stays open.
Deliver a chunk frame from the peer.
Deliver a STREAM_END frame from the peer.
Deliver a STREAM_ERROR frame from the peer.
Deliver a STREAM_REPLY frame from the peer.
Inspect stream state (debugging).
Pair two stream processes as peers (Phase 1 local dispatch).
Receive the next chunk (blocks indefinitely).
Send a binary chunk on the stream.
Server-side: emit a terminal error as the reply value.
Server-side: emit the terminal reply.
Start a stream gen_server.
Types
-type encoding() :: raw | msgpack.
-type mode() :: server_stream | client_stream | bidi.
-type role() :: client | server.
-type stream_id() :: binary().
Functions
Abort the stream with a STREAM_ERROR frame. Both sides close; any pending recv/await_reply waiters receive {error, {Code, Message}}.
Attach a V2 macula_station_link peer to this stream. The station_link carries deliveries as V2 macula_frame:stream_* frames over its peering connection (one per pool seed); inbound STREAM_* frames are decoded by the link and forwarded into this stream via the deliver_chunk / end / error / reply casts below.
Wait for the terminal reply (client-stream / bidi).
-spec close(pid()) -> ok.
Close both sides. Idempotent.
-spec close_send(pid()) -> ok.
Half-close the write side. Recv side stays open.
Deliver a chunk frame from the peer.
-spec deliver_end(pid(), send | both) -> ok.
Deliver a STREAM_END frame from the peer.
Deliver a STREAM_ERROR frame from the peer.
Deliver a STREAM_REPLY frame from the peer.
Inspect stream state (debugging).
Pair two stream processes as peers (Phase 1 local dispatch).
Receive the next chunk (blocks indefinitely).
Send a binary chunk on the stream.
Server-side: emit a terminal error as the reply value.
Server-side: emit the terminal reply.
Start a stream gen_server.
Required opts: id, role, mode, owner.