Aria 2.0.0
C++23 MVVM framework (C++20 minimum) — reactive, coroutine-first, ABI-layered
Loading...
Searching...
No Matches
dispatcher_executor.hpp
Go to the documentation of this file.
1#pragma once
2//
3// dispatcher_executor.hpp — adapters that bridge IDispatcher to IExecutor
4// and IDelayedScheduler. Moved from the Qt demo into the framework so
5// every platform host can reuse them without copy-pasting.
6//
7// Usage:
8// auto exec = std::make_shared<DispatcherExecutor>(my_dispatcher);
9// AsyncCommand<void> cmd{*exec, pool, ...};
10//
11
13#include "aria/property_ops.hpp"
15
16#include <chrono>
17#include <functional>
18#include <utility>
19
20namespace aria::runtime {
21
26public:
27 explicit DispatcherExecutor(IDispatcher& d) noexcept : d_(d) {}
28
29 void post(std::function<void()> fn) override { d_.post(std::move(fn)); }
30
41
42 [[nodiscard]] bool is_main_thread() const noexcept override {
43 return d_.is_main_thread();
44 }
45
46private:
47 IDispatcher& d_;
48};
49
54public:
55 explicit DispatcherScheduler(IDispatcher& d) noexcept : d_(d) {}
56
57 void post_after(std::chrono::milliseconds delay,
58 std::function<void()> fn) override {
59 d_.post_delayed(delay, std::move(fn));
60 }
61
62 [[nodiscard]] bool is_main_thread() const noexcept override {
63 return d_.is_main_thread();
64 }
65
72
73 void schedule(std::function<void()> fn) override {
74 d_.post(std::move(fn));
75 }
76
77 void schedule_after(std::chrono::milliseconds delay,
78 std::function<void()> fn) override {
79 d_.post_delayed(delay, std::move(fn));
80 }
81
82private:
83 IDispatcher& d_;
84};
85
86} // namespace aria::runtime
Tiny interface — anything that can post a function to run after a delay.
Definition property_ops.hpp:62
Abstract executor interface — schedules a callable to run "somewhere".
Definition executor.hpp:36
aria::SchedulerCaps caps() const noexcept override
Dispatcher-backed executor: safe as graph executor (main-thread affinity), safe as worker (posts land...
Definition dispatcher_executor.hpp:34
void post(std::function< void()> fn) override
Legacy / canonical executor entry point.
Definition dispatcher_executor.hpp:29
bool is_main_thread() const noexcept override
True iff the calling thread is the scheduler's "main" thread.
Definition dispatcher_executor.hpp:42
DispatcherExecutor(IDispatcher &d) noexcept
Definition dispatcher_executor.hpp:27
bool is_main_thread() const noexcept override
True iff the calling thread is the scheduler's "main" thread.
Definition dispatcher_executor.hpp:62
aria::SchedulerCaps caps() const noexcept override
Capability bitmask.
Definition dispatcher_executor.hpp:66
DispatcherScheduler(IDispatcher &d) noexcept
Definition dispatcher_executor.hpp:55
void schedule_after(std::chrono::milliseconds delay, std::function< void()> fn) override
Submit fn for execution after delay.
Definition dispatcher_executor.hpp:77
void post_after(std::chrono::milliseconds delay, std::function< void()> fn) override
Legacy / canonical timer entry point.
Definition dispatcher_executor.hpp:57
void schedule(std::function< void()> fn) override
Submit fn for execution "soon". Defines Caps::Post.
Definition dispatcher_executor.hpp:73
Abstract main-thread dispatcher.
Definition dispatcher.hpp:26
Definition container.hpp:11
SchedulerCaps
Definition scheduler.hpp:83
@ Post
Can submit "fire now" work.
Definition scheduler.hpp:89
@ GraphSafe
Safe to use as the graph-thread executor — i.e.
Definition scheduler.hpp:107
@ Pumpable
Posted work is held in a queue until a pump-style call drains it (e.g.
Definition scheduler.hpp:102
@ Delay
Can submit work after a wall-clock or virtual-time delay.
Definition scheduler.hpp:93
@ MainThread
Submitted work runs on a single, identifiable "main" thread that is consistent across calls.
Definition scheduler.hpp:97
@ WorkerSafe
Safe to host blocking worker tasks (e.g.
Definition scheduler.hpp:111