circuits-agent
Safe HaskellNone
LanguageGHC2024

Circuit.Agent.Turn

Description

Named runner circuits that tie free dual ends into a turn.

A turn is a runner observation: it commits one token, then blocks on one frame. Framing lives port-side (StdPorts stream marks); the queue retry is the blocking boundary. No polling, no backoff — the halt is decided by content, not inferred from quiet.

The correlation between a command and its response is carried by the TurnToken envelope, not by pipe adjacency. The mediator's residual state holds the pending command; a response matches when its thread cites the command's id. This makes zero-frame and two-frame failures detectable in-band rather than by positional guess.

Mark-carrying turns must use a Linear channel policy; weakening policies can drop a command or response and break correlation.

  turn e        :: IO (Loop (,) (K IO) Text Text)
  turnTimeout u e :: IO (Loop (,) (K IO) Text (Maybe Text))
Synopsis

Turn envelope

data TurnToken a Source #

A turn envelope. Commands are sent with an empty turnThread; the turn assigns them a fresh id. Responses must carry that id in their turnThread to be matched with the pending command.

Constructors

TurnToken 

Fields

Instances

Instances details
Eq a => Eq (TurnToken a) Source # 
Instance details

Defined in Circuit.Agent.Turn

Methods

(==) :: TurnToken a -> TurnToken a -> Bool #

(/=) :: TurnToken a -> TurnToken a -> Bool #

Show a => Show (TurnToken a) Source # 
Instance details

Defined in Circuit.Agent.Turn

Turn process

data TurnState a Source #

Residual state of the turn mediator. nextId supplies fresh command ids; pending holds the command awaiting its response.

Constructors

TurnState 

Instances

Instances details
Eq a => Eq (TurnState a) Source # 
Instance details

Defined in Circuit.Agent.Turn

Methods

(==) :: TurnState a -> TurnState a -> Bool #

(/=) :: TurnState a -> TurnState a -> Bool #

Show a => Show (TurnState a) Source # 
Instance details

Defined in Circuit.Agent.Turn

turnProcess :: Process (TurnToken a) (Maybe (TurnToken a, TurnToken a)) Source #

Process that correlates responses with the pending command by thread.

  • A token with empty thread is treated as a command: it receives the next id and is stored as the pending command.
  • A token with non-empty thread is treated as a response: it matches when its thread equals the pending command's id, emitting the pair.

Runner circuits

turn :: Poles (K IO) (TurnToken Text) (TurnToken Text) -> IO (Trace (,) (K IO) Text Text) Source #

Run one turn: commit a body, then block until a matching response arrives. The correlation is by thread, not by position.

turnTimeout :: Int -> Poles (K IO) (TurnToken Text) (TurnToken Text) -> IO (Trace (,) (K IO) Text (Maybe Text)) Source #

turn under a deadline (microseconds). Nothing on expiry; the unarrived response is not lost — the next emit still receives it.