pub struct SharedState { /* private fields */ }Expand description
A thread-safe, async, string→JSON store shared by all executors in a run.
Cheap to clone (an Arc handle); clones share the same underlying store.
Guards against concurrent access with a tokio::sync::RwLock. See the
module docs for the staged (pending/committed) superstep semantics.
Warning: keys beginning with _ are reserved for internal framework use.
Implementations§
Sourcepub fn new() -> SharedState
pub fn new() -> SharedState
Create an empty shared state.
Sourcepub async fn get(&self, key: &str) -> Option<Value>
pub async fn get(&self, key: &str) -> Option<Value>
Get a value by key, if present. Checks the pending buffer first (so an executor observes its own writes) and then committed state.
Sourcepub async fn set(&self, key: impl Into<String>, value: impl Into<Value>)
pub async fn set(&self, key: impl Into<String>, value: impl Into<Value>)
Stage a value for key, overwriting any existing pending write. The
value is visible to subsequent SharedState::get calls but is not
folded into committed state until SharedState::commit.
Sourcepub async fn has(&self, key: &str) -> bool
pub async fn has(&self, key: &str) -> bool
Whether a key exists in pending (as a non-tombstone) or committed state.
Sourcepub async fn delete(&self, key: &str) -> bool
pub async fn delete(&self, key: &str) -> bool
Stage a deletion of key, returning whether the key currently exists.
If the key exists only in the pending buffer it is removed there; if it
exists in committed state a tombstone is staged so the key is removed at
SharedState::commit.
Sourcepub async fn update<F>(&self, key: impl Into<String>, f: F)
pub async fn update<F>(&self, key: impl Into<String>, f: F)
Atomically read-modify-write a key under the write lock, staging the result into the pending buffer.
The closure receives the current value (pending-first, then committed)
or None and returns the new value to stage. Rust analogue of Python’s
hold/set_within_hold pattern for a single key.
Sourcepub async fn commit(&self)
pub async fn commit(&self)
Fold all pending writes into committed state and clear the buffer.
Called by the runner at each superstep boundary, after the superstep’s executors finish successfully and before checkpointing.
Sourcepub async fn export(&self) -> HashMap<String, Value>
pub async fn export(&self) -> HashMap<String, Value>
Export a snapshot copy of the committed state (used for checkpointing). Pending writes are deliberately excluded.
Trait Implementations§
Source§fn clone(&self) -> SharedState
fn clone(&self) -> SharedState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more