morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::reactive::Runtime Class Reference

The owner of a signal graph: every node takes one, and every operation runs on its owner. More...

#include <runtime.hpp>

Public Member Functions

 Runtime (exec::IExecutor &owner, RuntimeOptions options={})
 ~Runtime ()
 Reports detail::site::kRuntimeOutlived when nodes made from it are still alive, then detaches the core, so a flush still posted does nothing.
 Runtime (Runtime const &)=delete
Runtime & operator= (Runtime const &)=delete
 Runtime (Runtime &&)=delete
Runtime & operator= (Runtime &&)=delete
template<typename F>
decltype(auto) batch (F &&fn)
 Runs fn as one batch: every write inside it is one flush.
template<typename F>
decltype(auto) widgetEvent (F &&fn)
 Runs a widget callback as one batch. A flush that falls due while it runs, or that a nested event loop inside it (a modal dialog) picks up, is deferred: the end of the outermost widget event posts it. So a remount never destroys a widget whose native handler is on the stack, and a nested loop does not spin on a flush it may not run. The callback is untracked, like untracked: a widget callback is a transition, so one dispatched from inside an Effect's run does not subscribe that Effect to what it reads.
template<typename F>
decltype(auto) untracked (F &&fn) const
 Runs fn with tracking off: reads inside it subscribe nothing.
exec::IExecutor & owner () const noexcept
 The owner executor.
bool isFlushRequested () const noexcept
 Whether a flush is posted and has not run yet.
RuntimeStats stats () const
 What the runtime has counted so far. Read it on the owner.
std::shared_ptr< detail::RuntimeCore > const & core () const noexcept
 The shared core every node holds.

Detailed Description

The owner of a signal graph: every node takes one, and every operation runs on its owner.

Writes are batched. When the outermost batch ends with effects queued, the runtime posts one flush to the owner; no Effect ever runs inside set(). Destroying a Runtime while nodes made from it are alive is reported (detail::site::kRuntimeOutlived); the nodes stay valid and any flush does nothing.

Off the owner, batch, widgetEvent and untracked are reported (detail::site::kOffOwner) and refused: the body still runs, because the caller may need what it returns, but the runtime's state (batch depth, widget-event depth, tracking frame) is left alone, and each graph operation inside the body is checked, reported and refused on its own.

Definition at line 70 of file runtime.hpp.

Constructor & Destructor Documentation

◆ Runtime()

morph::reactive::Runtime::Runtime ( exec::IExecutor & owner,
RuntimeOptions options = {} )
inlineexplicit
Parameters
ownerThe executor the graph belongs to (the GUI or loop executor). It must be serial (IExecutor::isSerial), queue what is posted and run it later, in order, as Completion requires of its owner: one that runs a post inline would run Effects inside set(), and a pool would run two flushes at once. Borrowed: it must outlive the Runtime and every node made from it.
optionsFlush bounds and after-flush hook.
Exceptions
std::invalid_argumentwhen owner is not serial.

Definition at line 78 of file runtime.hpp.

◆ ~Runtime()

morph::reactive::Runtime::~Runtime ( )
inline

Reports detail::site::kRuntimeOutlived when nodes made from it are still alive, then detaches the core, so a flush still posted does nothing.

Definition at line 87 of file runtime.hpp.

Member Function Documentation

◆ batch()

template<typename F>
decltype(auto) morph::reactive::Runtime::batch ( F && fn)
inline

Runs fn as one batch: every write inside it is one flush.

Template Parameters
FA callable taking no arguments.
Parameters
fnThe body. Writes made before it throws still flush.
Returns
Whatever fn returns.

Definition at line 104 of file runtime.hpp.

◆ widgetEvent()

template<typename F>
decltype(auto) morph::reactive::Runtime::widgetEvent ( F && fn)
inline

Runs a widget callback as one batch. A flush that falls due while it runs, or that a nested event loop inside it (a modal dialog) picks up, is deferred: the end of the outermost widget event posts it. So a remount never destroys a widget whose native handler is on the stack, and a nested loop does not spin on a flush it may not run. The callback is untracked, like untracked: a widget callback is a transition, so one dispatched from inside an Effect's run does not subscribe that Effect to what it reads.

Template Parameters
FA callable taking no arguments.
Parameters
fnThe callback.
Returns
Whatever fn returns.

Definition at line 122 of file runtime.hpp.

◆ untracked()

template<typename F>
decltype(auto) morph::reactive::Runtime::untracked ( F && fn) const
inline

Runs fn with tracking off: reads inside it subscribe nothing.

Template Parameters
FA callable taking no arguments.
Parameters
fnThe body.
Returns
Whatever fn returns.

Definition at line 136 of file runtime.hpp.

◆ owner()

exec::IExecutor & morph::reactive::Runtime::owner ( ) const
inlinenodiscardnoexcept

The owner executor.

Returns
The executor passed at construction.

Definition at line 146 of file runtime.hpp.

◆ isFlushRequested()

bool morph::reactive::Runtime::isFlushRequested ( ) const
inlinenodiscardnoexcept

Whether a flush is posted and has not run yet.

Returns
True between the first write that queued an Effect and the flush.

Definition at line 150 of file runtime.hpp.

◆ stats()

RuntimeStats morph::reactive::Runtime::stats ( ) const
inlinenodiscard

What the runtime has counted so far. Read it on the owner.

Returns
The counts.

Definition at line 154 of file runtime.hpp.

◆ core()

std::shared_ptr< detail::RuntimeCore > const & morph::reactive::Runtime::core ( ) const
inlinenodiscardnoexcept

The shared core every node holds.

Returns
The core.

Definition at line 170 of file runtime.hpp.


The documentation for this class was generated from the following file: