2#include <asyncpp/dispatcher.h>
5#include <condition_variable>
16 std::condition_variable m_cv;
17 std::deque<std::function<void()>> m_queue;
18 std::atomic<bool> m_done =
false;
25 void push(std::function<
void()> cbfn)
override {
27 std::unique_lock lck{m_mtx};
28 m_queue.emplace_back(std::move(cbfn));
36 std::unique_lock lck{m_mtx};
47 std::unique_lock lck{m_mtx};
48 if (m_queue.empty()) {
52 auto cbfn = std::move(m_queue.front());
Basic dispatcher interface class.
Definition dispatcher.h:8
static dispatcher * current() noexcept
Definition dispatcher.h:48
A very basic dispatcher that runs in a single thread until manually stopped.
Definition simple_dispatcher.h:14
void run()
Block and process tasks pushed to it until stop is called.
Definition simple_dispatcher.h:44
void stop() noexcept
Stop the dispatcher. It will return the on the next iteration, regardless if there is any work left.
Definition simple_dispatcher.h:35
void push(std::function< void()> cbfn) override
Push a function to be executed on the dispatcher.
Definition simple_dispatcher.h:25