Skip to main content

Module state

Module state 

Source
Expand description

Generic “latest-snapshot” state cell over tokio::sync::watch.

Single source of truth for the “hold a value, broadcast on change, let consumers pull snapshots” pattern. Used by [moonproof_wallet::runtime::WalletRuntime] (over FacadeState) and [moonproof_runtime::sync::Watcher] (over ContractRuntimeState). Each consumer composes its own cancel/lifecycle on top — this primitive only owns the state + change broadcast.

Distinct from crate::events::EventBus, which is a per-event firehose (broadcast). State cell is “latest value + change signal” (watch). Pick whichever fits the domain — they don’t overlap.

Structs§

StateCell
Holds the current value of T behind an Arc<RwLock>, plus a tokio::sync::watch channel that fires every time the value changes. Cheap to clone — the inner state + sender are Arc-shared.