pub async fn run_coordinator(
coord: Arc<SagaCoordinator>,
events_rx: Receiver<Event>,
)Expand description
Run the coordinator’s bus-subscription loop.
Receiver is passed in, not subscribed inside. Subscribing
before tokio::spawn (in main.rs) ensures events emitted
between coordinator construction and the first recv() aren’t
lost to the race window. Same pattern as event_log::run_disk_writer.
(reagent P2 PR #609.)
Dispatch order on each event:
- Match against trigger table → start any new sagas via
spawn_saga(which emitsSagaStartedand applies the saga’s initial action). - Feed the same event into every in-flight saga’s
on_event. Sagas returningDone/Failedare removed fromin_flightafter their lifecycle event is emitted.
Self-emitted events (SagaStarted / SagaCompleted /
SagaFailed) are NOT re-fed into sagas. A saga reacting to its
own start event would loop. Filtered at the top of the dispatch
path.