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...
|
| | MainThreadExecutor ()=default |
| | MainThreadExecutor (const MainThreadExecutor &)=delete |
| MainThreadExecutor & | operator= (const MainThreadExecutor &)=delete |
| | MainThreadExecutor (MainThreadExecutor &&)=delete |
| MainThreadExecutor & | operator= (MainThreadExecutor &&)=delete |
| | ~MainThreadExecutor () override |
| 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 () |
| | Drop all pending callables without running them. Owner-thread-only.
|
| | ~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.
|
| 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 throw std::logic_error in every build.
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: