Skip to main content

Module shared_async_pointer

Module shared_async_pointer 

Source
Expand description

SharedAsyncPointer<T> - cross-process lazy / speculative resolution wrapping a SharedOnceCell<T>.

Three resolution strategies; all converge to a single canonical value in the underlying SharedOnceCell:

StrategyRace widthFailover
Resolvedn/an/a (value pre-set)
Lazy1first caller to set wins; others read
SpeculativeN (workers)first-publisher-wins; losers discard

§The Speculative race

get_or_speculative(n, f) spawns N worker threads (or in the cross-process variant, dispatches N Passes via the BackgroundScheduler). Each worker independently computes f() and CAS-attempts to publish the result via the underlying SharedOnceCell. The first to win the CAS becomes the canonical result; losers see the cell already filled and DISCARD their result.

This is the architectural novelty: redundant cross-process compute with first-publisher-wins. No existing Rust async runtime provides this primitive. It’s useful for:

  • Latency hedging: race 2-3 backend lookups, take the fastest
  • Survivability: race N solvers across processes; any one surviving suffices
  • Fault-tolerant fetch: if one resolver dies, others continue

Failover within 1 epoch: if a resolver dies mid-compute, the others are unaffected; the first survivor publishes. No coordinator needed - the CAS protocol IS the coordination.

Modules§

strategy
Strategy tag observed by the substrate.

Structs§

SharedAsyncPointer

Enums§

SharedAsyncError