run_coordinator

Function run_coordinator 

Source
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:

  1. Match against trigger table → start any new sagas via spawn_saga (which emits SagaStarted and applies the saga’s initial action).
  2. Feed the same event into every in-flight saga’s on_event. Sagas returning Done / Failed are removed from in_flight after 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.