Skip to main content

Module event_driven

Module event_driven 

Source
Expand description

EventDrivenController — generic adapter that ticks a wrapped Controller on every received event.

Bridges any tokio broadcast channel (engenho-store WatchEvent, engenho-substrate CacheEvent, custom event sources) into the Controller trait surface — controllers no longer need to poll when the upstream can notify.

§Reconcile semantics

  • tick() on EventDrivenController = drain pending events + issue ONE downstream tick() per event (or one per batch when coalesce: true).
  • Lagged subscribers (broadcast capacity overflow) → ignored; one extra tick scheduled to catch up.
  • Closed channels → returns Ok with the count of events processed before close. Subsequent ticks no-op until the receiver is resubscribed.

§When to use

  • Wrap DrvController so it ticks on CacheEvent::RealisationUpserted instead of running on every interval.
  • Wrap any Controller whose upstream emits typed events.

§When NOT to use

  • Controllers whose state isn’t event-derived (TickEvery is fine for those).
  • Cross-cluster federation paths where event order isn’t guaranteed (use a reconcile loop with full-list reads).

Structs§

EventDrivenController
Generic wrapper that drains an event channel + issues ticks.