circuits-agent
Safe HaskellNone
LanguageGHC2024

Circuit.Agent.Machina.Mark

Description

Mark-driven halt machinery for STM agents.

This module graduates the first machina probe-station combinator into circuits-agent. The design principle: the builder posts its silence as a token, and the runner halts on that read. There is no orElse fallback — absence is not an opinion here. If the mark never arrives, the runner blocks; the halt is decided by content, not inferred from quiet.

The 'Loop Either' form pushes the same halt to the surface of a composition: Left = continue, Right = halt. This makes the mark-halt a trace citizen, with the continuation folded away by trace.

The rest of the machina probe station (quiet ends, sealed ends, stream ends) stays in circuits-agent-machina until a consumer appears here.

Synopsis

Mark-driven halt

spinMark :: (a -> Bool) -> (s -> a -> s) -> Poles (K STM) a a -> K STM s s Source #

Spin until the mark is read: the builder posts its silence as a token, and the runner halts on that read. No orElse — absence is not an opinion here. If the mark never arrives, this blocks; the halt is decided by content, not inferred from quiet.

Contrast a plain retry-driven spin: that frame drains the queue and falls through on absence; mark-driven halt is decisive mid-stream — tokens after the mark are never consumed.

markLoop :: (a -> Bool) -> (s -> a -> s) -> Poles (K STM) a a -> Trace Either (K STM) s s Source #

The mark-halt pushed to the surface of a composition: a Trace Either citizen. The halt decision travels as data through the channel and the trace folds the continuation away — the runner is a value, not a loop spelled in fix.