From 8425900fe08b2afd603c3c920eac18a06cc3ab5a Mon Sep 17 00:00:00 2001 From: lisyarus Date: Mon, 26 Dec 2022 14:06:39 +0300 Subject: [PATCH] Implement synchronous implementation of async::executor --- .../psemek/async/synchronous_executor.hpp | 26 ++++++++++++++ libs/async/source/synchronous_executor.cpp | 35 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 libs/async/include/psemek/async/synchronous_executor.hpp create mode 100644 libs/async/source/synchronous_executor.cpp diff --git a/libs/async/include/psemek/async/synchronous_executor.hpp b/libs/async/include/psemek/async/synchronous_executor.hpp new file mode 100644 index 00000000..45b6fa3f --- /dev/null +++ b/libs/async/include/psemek/async/synchronous_executor.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include + +namespace psemek::async +{ + + struct synchronous_executor + : executor + { + void post(task t) override; + + void post_at(clock::time_point time, task t) override; + + void stop() override; + + void wait() override; + + void wait_for(clock::duration period) override; + + void wait_until(clock::time_point time) override; + + std::size_t task_count() const override; + }; + +} diff --git a/libs/async/source/synchronous_executor.cpp b/libs/async/source/synchronous_executor.cpp new file mode 100644 index 00000000..45eadb09 --- /dev/null +++ b/libs/async/source/synchronous_executor.cpp @@ -0,0 +1,35 @@ +#include + +#include + +namespace psemek::async +{ + + void synchronous_executor::post(task t) + { + t(); + } + + void synchronous_executor::post_at(clock::time_point, task) + { + throw std::runtime_error("synchronous_executor doesn't support executor::post_at"); + } + + void synchronous_executor::stop() + {} + + void synchronous_executor::wait() + {} + + void synchronous_executor::wait_for(clock::duration) + {} + + void synchronous_executor::wait_until(clock::time_point) + {} + + std::size_t synchronous_executor::task_count() const + { + return 0; + } + +}