38 std::shared_ptr<boost::asio::cancellation_slot> cancel_slot,
39 std::string_view processor_name) -> boost::asio::awaitable<void>
41 spdlog::trace(
"[{}] Coroutine started", processor_name);
43 co_await proc->run(cancel_slot);
44 }
catch (
const boost::system::system_error &err) {
45 if (err.code() == boost::asio::error::operation_aborted
46 or err.code() == boost::asio::experimental::error::channel_cancelled
47 or err.code() == boost::asio::experimental::error::channel_closed) {
48 spdlog::debug(
"[{}] Cancelled, exiting run loop", processor_name);
51 spdlog::error(
"[{}] Unexpected error in run_once: {}", processor_name, err.what());
52 }
catch (
const std::exception &err) {
53 spdlog::error(
"[{}] Unknown exception in run_once: {}", processor_name, err.what());
55 spdlog::trace(
"[{}] Coroutine exiting", processor_name);
79 std::shared_ptr<P> proc,
80 std::shared_ptr<boost::asio::cancellation_slot> cancel_slot,
81 std::string_view processor_name) -> std::shared_ptr<coroutine_state>
83 auto state = std::make_shared<coroutine_state>();
84 boost::asio::co_spawn(
86 [](std::shared_ptr<P> processor,
87 std::shared_ptr<boost::asio::cancellation_slot> c_slot,
88 std::string_view name,
89 std::shared_ptr<coroutine_state> coro_state) -> boost::asio::awaitable<void> {
90 coro_state->started =
true;
92 coro_state->done =
true;
93 }(proc, cancel_slot, processor_name, state),
94 boost::asio::detached);
auto spawn_processor(const std::shared_ptr< boost::asio::io_context > &io_ctx, std::shared_ptr< P > proc, std::shared_ptr< boost::asio::cancellation_slot > cancel_slot, std::string_view processor_name) -> std::shared_ptr< coroutine_state >
Spawns a processor as a detached coroutine.
auto run_processor(std::shared_ptr< P > proc, std::shared_ptr< boost::asio::cancellation_slot > cancel_slot, std::string_view processor_name) -> boost::asio::awaitable< void >
Runs a processor coroutine with error handling.