19#ifndef WORKER_HPP_INCLUDED
20#define WORKER_HPP_INCLUDED
27#include "asio/io_context.hpp"
28#include "asio/any_io_executor.hpp"
29#include "asio/executor_work_guard.hpp"
43 asio::io_context m_ioc;
44 asio::executor_work_guard<asio::io_context::executor_type> m_wg;
45 std::thread m_run_thr;
48 worker() : m_ioc(), m_wg(asio::make_work_guard(m_ioc)), m_run_thr() { }
62 m_run_thr = std::thread([
this] () {
66 catch (
const std::exception& e) {
67 std::cerr <<
"std::exception caught in worker::start: " << e.what() << std::endl;
70 std::cerr <<
"Unknown exception caught in worker::start" << std::endl;
Convenience class that combines an executor work guard and a thread, invoking asynchronous operations...
Definition worker.hpp:41
void stop()
Shutdown the executor and join the thread, abandoning any outstanding operations or handlers.
Definition worker.hpp:79
void start()
Start the thread that invokes the underlying asynchronous operations.
Definition worker.hpp:61
asio::io_context & get_io_context()
Provide access to the io_context.
Definition worker.hpp:55
void reset()
Reset the internal work guard and join the thread, waiting for outstanding operations or handlers to ...
Definition worker.hpp:88