Interface SharedState<T>

Type Parameters:
T - the value type
All Superinterfaces:
StateToken
All Known Implementing Classes:
SharedStateImpl

public interface SharedState<T> extends StateToken
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 Type
    Method
    Description
    get()
    Returns the current shared value.
    void
    set(T value)
    Atomically replaces the shared value and triggers a watcher flush for every open session of the owning view.
    void
    update(@NotNull UnaryOperator<T> fn)
    Atomically updates the shared value with a compare-and-set loop; fn may run more than once under contention and must be side-effect free.
  • Method Details

    • get

      @Nullable T get()
      Returns the current shared value.
      Returns:
      the current value, possibly null
    • set

      void set(@Nullable T value)
      Atomically replaces the shared value and triggers a watcher flush for every open session of the owning view.
      Parameters:
      value - the new value, possibly null
    • update

      void update(@NotNull @NotNull UnaryOperator<T> fn)
      Atomically updates the shared value with a compare-and-set loop; fn may run more than once under contention and must be side-effect free.
      Parameters:
      fn - the function producing the new value from the current one