Implement synchronous implementation of async::executor

This commit is contained in:
Nikita Lisitsa 2022-12-26 14:06:39 +03:00
parent 9600bd96d5
commit 8425900fe0
2 changed files with 61 additions and 0 deletions

View file

@ -0,0 +1,26 @@
#pragma once
#include <psemek/async/executor.hpp>
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;
};
}

View file

@ -0,0 +1,35 @@
#include <psemek/async/synchronous_executor.hpp>
#include <stdexcept>
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;
}
}