libs/corosio/src/corosio/src/detail/dispatch_coro.hpp

100.0% Lines (4/4) 100.0% Functions (1/1) 100.0% Branches (2/2)
libs/corosio/src/corosio/src/detail/dispatch_coro.hpp
Line Branch Hits Source Code
1 //
2 // Copyright (c) 2026 Vinnie Falco (vinnie.falco@gmail.com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/cppalliance/corosio
8 //
9
10 #ifndef BOOST_COROSIO_DETAIL_DISPATCH_CORO_HPP
11 #define BOOST_COROSIO_DETAIL_DISPATCH_CORO_HPP
12
13 #include <boost/corosio/basic_io_context.hpp>
14 #include <boost/capy/ex/executor_ref.hpp>
15 #include <boost/capy/detail/type_id.hpp>
16 #include <coroutine>
17
18 namespace boost::corosio::detail {
19
20 /** Returns a handle for symmetric transfer on I/O completion.
21
22 If the executor is io_context::executor_type, returns `h`
23 directly (fast path). Otherwise dispatches through the
24 executor, which returns `h` or `noop_coroutine()`.
25
26 Callers in coroutine machinery should return the result
27 for symmetric transfer. Callers at the scheduler pump
28 level should call `.resume()` on the result.
29
30 @param ex The executor to dispatch through.
31 @param h The coroutine handle to resume.
32
33 @return A handle for symmetric transfer or `std::noop_coroutine()`.
34 */
35 inline std::coroutine_handle<>
36 263216 dispatch_coro(
37 capy::executor_ref ex,
38 std::coroutine_handle<> h)
39 {
40
2/2
✓ Branch 2 taken 263207 times.
✓ Branch 3 taken 9 times.
263216 if (&ex.type_id() == &capy::detail::type_id<basic_io_context::executor_type>())
41 263207 return h;
42 9 return ex.dispatch(h);
43 }
44
45 } // namespace boost::corosio::detail
46
47 #endif
48