3#include <boost/asio/io_context.hpp>
4#include <boost/asio/strand.hpp>
8namespace malloy::detail
21 template<
typename Executor>
24 using act_t = std::function<void(
const std::function<
void()>&)>;
25 using acts_t = std::queue<act_t>;
26 using ioc_t = boost::asio::strand<Executor>;
50 boost::asio::dispatch(m_ioc, [
this, act = std::move(act)]()
mutable ->
void {
51 m_acts.push(std::move(act));
52 if (!m_currently_running_act) {
75 m_currently_running_act =
true;
78 boost::asio::dispatch(m_ioc, [
this] {
79 if (!m_acts.empty()) {
80 auto act = std::move(m_acts.front());
82 std::invoke(std::move(act), [this] {
86 m_currently_running_act = false;
92 m_currently_running_act =
false;
98 std::atomic_bool m_running{
false};
99 std::atomic_bool m_currently_running_act{
false};
Stores and executes functions.
Definition: action_queue.hpp:23
void push(act_t act)
Add an action to the queue.
Definition: action_queue.hpp:48
action_queue(ioc_t ioc)
Construct the action queue. It will not execute anything until run() is called.
Definition: action_queue.hpp:35
void run()
Starts the queue running, if it isn't already.
Definition: action_queue.hpp:64