Interface SharedState<T>
- Type Parameters:
T- the value type
- All Superinterfaces:
StateToken
- All Known Implementing Classes:
SharedStateImpl
One value per view singleton, shared by all viewers; not context-keyed. All methods are
atomic and callable from any thread; the watcher flush for open sessions is marshalled
to the main thread and coalesced per view per tick.
-
Method Summary
Modifier and TypeMethodDescriptionget()Returns the current shared value.voidAtomically replaces the shared value and triggers a watcher flush for every open session of the owning view.voidupdate(@NotNull UnaryOperator<T> fn) Atomically updates the shared value with a compare-and-set loop;fnmay run more than once under contention and must be side-effect free.
-
Method Details
-
get
Returns the current shared value.- Returns:
- the current value, possibly
null
-
set
Atomically replaces the shared value and triggers a watcher flush for every open session of the owning view.- Parameters:
value- the new value, possiblynull
-
update
Atomically updates the shared value with a compare-and-set loop;fnmay run more than once under contention and must be side-effect free.- Parameters:
fn- the function producing the new value from the current one
-