|
Aria 2.0.0
C++23 MVVM framework (C++20 minimum) — reactive, coroutine-first, ABI-layered
|
Main-thread executor — queues callables for later execution on the thread that "owns" the executor (typically the application's main thread or a test thread). More...
#include <executor.hpp>
Public Member Functions | |
| void | post (std::function< void()> fn) override |
| Legacy / canonical executor entry point. | |
| aria::SchedulerCaps | caps () const noexcept override |
| Main-thread executor: safe in both reactive roles, plus Pumpable (drain/pump_until/run_one) and MainThread (owner-thread affinity is enforced after first pump). | |
| bool | is_main_thread () const noexcept override |
| True iff the calling thread is the scheduler's "main" thread. | |
| std::size_t | drain () |
| Run callables. | |
| template<typename Pred> | |
| bool | pump_until (Pred predicate, std::chrono::milliseconds timeout=std::chrono::seconds{2}) |
| Pump until predicate() returns true OR timeout elapses, then return. | |
| void | run_one () |
| Run exactly one callable, blocking the owner thread until one is available. | |
| bool | is_owner_thread () const noexcept |
| True if called from the thread that owns this executor (or if no owner has been bound yet). | |
| std::size_t | pending () const noexcept |
| void | clear () noexcept |
| Drop all pending callables without running them. Owner-thread-only. | |
| Public Member Functions inherited from aria::async::IExecutor | |
| ~IExecutor () override=default | |
| void | schedule (std::function< void()> fn) override |
| Submit fn for execution "soon". Defines Caps::Post. | |
| virtual bool | is_safe_graph_executor () const noexcept |
| True iff this executor is safe to use as the graph-thread (UI) executor. | |
| virtual bool | is_safe_worker_executor () const noexcept |
| True iff this executor can host worker tasks. | |
| Public Member Functions inherited from aria::IScheduler | |
| virtual | ~IScheduler ()=default |
| virtual void | schedule_after (std::chrono::milliseconds delay, std::function< void()> fn) |
| Submit fn for execution after delay. | |
Main-thread executor — queues callables for later execution on the thread that "owns" the executor (typically the application's main thread or a test thread).
MainThreadExecutor is the canonical graph-thread executor for any scenario that mixes a thread-pool worker with reactive Property writes. The owner thread is established lazily by the first call to drain(), pump_until() or pump_one(); subsequent attempts to pump from a different thread trip a debug assert (and a runtime throw in Release).
Usage (test):
MainThreadExecutor ui; // declared on the test thread ThreadPoolExecutor pool{4};
AsyncCommand<int, int> cmd{ui, pool, ...}; cmd.execute(7); // Pump until the coroutine has marshalled its Property writes // back to the graph thread. REQUIRE(ui.pump_until([&]{ return !cmd.is_executing.get(); }));
Usage (console / headless app):
MainThreadExecutor main_loop; set_main_executor(main_loop); // ... wire up your ViewModels, Commands, etc. ... while (running) main_loop.run_one(); // blocks until next post
Thread-safety:
|
inlineoverridevirtual |
Legacy / canonical executor entry point.
Implementations override this; the unified IScheduler::schedule(fn) is wired to it.
Implements aria::async::IExecutor.
|
inlinenodiscardoverridevirtualnoexcept |
Main-thread executor: safe in both reactive roles, plus Pumpable (drain/pump_until/run_one) and MainThread (owner-thread affinity is enforced after first pump).
Reimplemented from aria::async::IExecutor.
|
inlinenodiscardoverridevirtualnoexcept |
True iff the calling thread is the scheduler's "main" thread.
Default returns false; implementations advertising Caps::MainThread SHOULD override with a meaningful answer.
Reimplemented from aria::IScheduler.
|
inline |
Run callables.
Drains recursively: any task that posts further callables on this executor (typical of coroutine resumption that schedules a follow-up on the same thread) will be picked up in the same call. Returns the total number of callables executed.
Owner-thread-only.
|
inline |
Pump until predicate() returns true OR timeout elapses, then return.
Blocks the owner thread on a condition variable when the queue is empty — no spin sleeping. Returns true iff predicate became true within the deadline.
Owner-thread-only.
|
inline |
Run exactly one callable, blocking the owner thread until one is available.
Suitable as the body of a console app's main loop.
Owner-thread-only.
|
inlinenodiscardnoexcept |
True if called from the thread that owns this executor (or if no owner has been bound yet).
|
inlinenodiscardnoexcept |
|
inlinenoexcept |
Drop all pending callables without running them. Owner-thread-only.