17#include <commons/display_info.hpp>
32 virtual void execute(std::function<
void()> task) = 0;
33 [[nodiscard]]
virtual std::string_view
name() const noexcept = 0;
40concept
Executor = requires(E& e, std::function<
void()> f) {
41 { e.execute(std::move(f)) } -> std::same_as<void>;
54inline void execute_on(Exec& exec, std::function<
void()> task) {
55 exec.execute(std::move(task));
70 void execute(
const std::function<
void()> task)
override {
76 [[nodiscard]] std::string_view
name() const noexcept
override {
81 static const comms::DisplayInfo info{
82 .name =
"InlineExecutor",
83 .description =
"Executor that runs tasks synchronously on the calling thread.",
84 .icon = comms::Icon::from(
"mdi:flash"),
96 requires Executor<Exec>
99 explicit ExecutorRef(Exec& e, std::string nm = {})
noexcept : exec_(&e), name_(std::move(nm)) {}
101 void execute(std::function<
void()> task)
override {
102 exec_->execute(std::move(task));
104 [[nodiscard]] std::string_view
name() const noexcept
override {
105 return name_.empty() ? std::string_view{
"executor-ref"} : std::string_view{name_};
Wraps any Executor-conforming type behind the virtual IExecutor interface, so functions that take IEx...
Definition executor.hpp:97
std::string_view name() const noexcept override
Definition executor.hpp:104
ExecutorRef(Exec &e, std::string nm={}) noexcept
Definition executor.hpp:99
void execute(std::function< void()> task) override
Definition executor.hpp:101
Virtual interface for "anything that can run a `std::function<void()>`".
Definition executor.hpp:29
virtual std::string_view name() const noexcept=0
virtual void execute(std::function< void()> task)=0
virtual ~IExecutor()=default
Runs task() synchronously on the calling thread.
Definition executor.hpp:63
std::string_view name() const noexcept override
Definition executor.hpp:76
void execute(const std::function< void()> task) override
Definition executor.hpp:70
static InlineExecutor & instance() noexcept
Definition executor.hpp:65
static const comms::DisplayInfo & display_info()
Definition executor.hpp:80
Duck-typed alternative to IExecutor for templated code that wants to avoid a virtual call.
Definition executor.hpp:40
Re-export <commons/display_info.hpp> and attach non-intrusive comms::HasDisplayInfo<> specializations...
Cached subsystem loggers for the tm.
void execute_on(IExecutor &exec, std::function< void()> task)
Dispatch helper used by Future::then / SharedFuture::then.
Definition executor.hpp:48
Definition exceptions.hpp:22