From 1d29260d77959e03a76d03010a4af4d1e1c46959 Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Mon, 14 Jul 2025 17:44:48 +0200 Subject: [PATCH] IoEngine: allow to bind to rvalue `Executor` objects Don't require the Executor to be of type non-const reference but allow it to be a forwarding reference instead. This allows us to use`IoEngine::SpawnCoroutine()` with both lvalue and rvalue executors. --- lib/base/io-engine.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/base/io-engine.hpp b/lib/base/io-engine.hpp index 0883d7810..3e0f5563a 100644 --- a/lib/base/io-engine.hpp +++ b/lib/base/io-engine.hpp @@ -103,8 +103,8 @@ public: #endif /* _WIN32 */ } - template - static void SpawnCoroutine(Handler& h, Function f) { + template + static void SpawnCoroutine(Executor&& e, Function f) { auto wrapper = [f = std::move(f)](boost::asio::yield_context yc) { try { f(yc); @@ -123,13 +123,14 @@ public: }; #if BOOST_VERSION >= 108700 - boost::asio::spawn(h, + boost::asio::spawn( + std::forward(e), std::allocator_arg, boost::context::fixedsize_stack(GetCoroutineStackSize()), std::move(wrapper), boost::asio::detached ); #else // BOOST_VERSION >= 108700 - boost::asio::spawn(h, std::move(wrapper), boost::coroutines::attributes(GetCoroutineStackSize())); + boost::asio::spawn(std::forward(e), std::move(wrapper), boost::coroutines::attributes(GetCoroutineStackSize())); #endif // BOOST_VERSION >= 108700 }