13#include "../attributes.hpp"
14#include "../core/executor.hpp"
22namespace morph::reactive {
79 : _core{makeCore(
owner)} {
80 _core->configure(
detail::FlushBounds{.maxEffectRunsPerFlush = options.maxEffectRunsPerFlush,
81 .maxThrowReposts = options.maxThrowReposts},
82 std::move(options.afterFlush));
88 if (_core->liveNodes() != 0) {
103 template <
typename F>
105 if (!_core->checkOwner()) {
106 return std::invoke(std::forward<F>(fn));
109 return std::invoke(std::forward<F>(fn));
121 template <
typename F>
123 if (!_core->checkOwner()) {
124 return std::invoke(std::forward<F>(fn));
128 return batch(std::forward<F>(fn));
135 template <
typename F>
137 if (!_core->checkOwner()) {
138 return std::invoke(std::forward<F>(fn));
141 return std::invoke(std::forward<F>(fn));
156 .effectsRun = _core->effectsRun(),
157 .lastFlushEffects = _core->lastFlushEffects(),
158 .maxFlushEffects = _core->maxFlushEffects(),
159 .batches = _core->batches(),
160 .misuses = _core->misuses(),
161 .recentMisuses = {}};
162 for (
char const*
const where : _core->recentMisuses()) {
170 [[nodiscard]] std::shared_ptr<detail::RuntimeCore>
const&
core() const noexcept {
return _core; }
175 throw std::invalid_argument{
"morph::reactive::Runtime: the owner executor must be serial"};
177 return std::make_shared<detail::RuntimeCore>(
owner);
180 std::shared_ptr<detail::RuntimeCore> _core;
The owner of a signal graph: every node takes one, and every operation runs on its owner.
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 loo...
Runtime(exec::IExecutor &owner, RuntimeOptions options={})
decltype(auto) batch(F &&fn)
Runs fn as one batch: every write inside it is one flush.
exec::IExecutor & owner() const noexcept
The owner executor.
decltype(auto) untracked(F &&fn) const
Runs fn with tracking off: reads inside it subscribe nothing.
~Runtime()
Reports detail::site::kRuntimeOutlived when nodes made from it are still alive, then detaches the cor...
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.
Opens a batch for its lifetime.
Collects the sources one tracked run reads, and restores the previous frame when it ends.
The reactive graph's internals: node colours and links, the tracking frame, batching and the flush qu...
constexpr std::size_t kDefaultMaxEffectRunsPerFlush
How many times one Effect may run in a single flush unless RuntimeOptions says otherwise.
constexpr std::size_t kDefaultMaxThrowReposts
How many flushes in a row are re-posted after an Effect threw, unless RuntimeOptions says otherwise.
constexpr char const * kRuntimeOutlived
A Runtime was destroyed while nodes made from it were alive.
Abstract executor interface.
virtual bool isSerial() const noexcept
Whether this executor runs one task at a time, each after the tasks posted before it: a strand,...
How a Runtime bounds and reports its flushes.
std::function< void()> afterFlush
Called on the owner after every flush that processed a queued Effect; a frontend schedules its redraw...
std::size_t maxThrowReposts
How many flushes in a row are re-posted after an Effect threw. Each re-post runs what is still queued...
std::size_t maxEffectRunsPerFlush
How many times one Effect may run in a single flush before the flush is treated as a write cycle,...
What a Runtime has counted since it was made: its flushes, the Effects they ran, its batches and the ...
std::uint64_t maxFlushEffects
The most queued Effects one flush processed.
std::uint64_t misuses
Misuses reported (detail::site), on the owner or off it.
std::uint64_t lastFlushEffects
Queued Effects the latest flush processed.
std::vector< std::string > recentMisuses
The sites of the latest misuses, oldest first, at most detail::kRecentMisuses.
std::uint64_t batches
Outermost batches opened.
std::uint64_t flushes
Flushes that ran at least one queued Effect.
std::uint64_t effectsRun
Queued Effects the flushes processed, in all.
The bounds a flush keeps, as RuntimeOptions sets them.