Template Class ObservedVariable

Class Documentation

template<typename T, std::uint8_t Observers = 1>
class ObservedVariable

Adds immediate observer callbacks to synchronized, versioned storage.

Every set() invokes observers on the calling thread, even when the value is unchanged. Waiters wake only for a changed value. Use CE::State::VersionedVariable directly when callback thread affinity is undesirable. Callbacks run in array order after releasing the storage mutex, with this set’s argument, not a later snapshot. Their const reference is borrowed for the call. Concurrent/reentrant sets can overlap callbacks; callbacks protect their own targets. A throw propagates after publication and skips later observers without rollback.

Public Types

using Callback = std::function<void(const T&)>

Public Functions

inline explicit ObservedVariable(T value, std::array<Callback, Observers> observers)
inline ObservedVariable &operator=(T value)
inline void set(T value)
inline T get() const

Declaration: [[nodiscard]]

inline ::CE::State::VersionedSnapshot<T> snapshot() const

Declaration: [[nodiscard]]

inline std::uint64_t revision() const

Declaration: [[nodiscard]]

inline ::CE::State::VersionedSnapshot<T> wait_for_change(std::uint64_t since) const

Declaration: [[nodiscard]]

inline void wait_until_change() const