Syntalos::LiveValue

Syntalos::LiveValue

Syntalos::LiveValue

A value that the main thread can change while a worker is running. More…

#include <moduleworker.h>

Public Functions

Name
LiveValue()
LiveValue(T initialValue)
voidset(T value)
Set a new value and flag it as changed.
Tget() const
Get a copy of the current value.
std::optional< T >takeIfChanged()
Get the value if it was set since the last call to this function.

Detailed Description

template <typename T >
class Syntalos::LiveValue;

A value that the main thread can change while a worker is running.

This is a handle: copies share the same value. The module keeps one copy and hands another one to its worker thread. Any thread may call set() and get(), while takeIfChanged() is meant for a single consumer, which picks up changes at a point where it is convenient for it.

Public Functions Documentation

function LiveValue

inline LiveValue()

function LiveValue

inline LiveValue(
    T initialValue
)

function set

inline void set(
    T value
)

Set a new value and flag it as changed.

function get

inline T get() const

Get a copy of the current value.

function takeIfChanged

inline std::optional< T > takeIfChanged()

Get the value if it was set since the last call to this function.

This is cheap if nothing has changed (a single atomic load), so it can be called in a tight loop.


Updated on 2026-11-26 at 18:54:14 +0000