Line data Source code
1 : //
2 : // Copyright (c) 2025 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/capy
8 : //
9 :
10 : #ifndef BOOST_CAPY_DETAIL_AWAIT_SUSPEND_HELPER_HPP
11 : #define BOOST_CAPY_DETAIL_AWAIT_SUSPEND_HELPER_HPP
12 :
13 : #include <coroutine>
14 : #include <boost/capy/ex/io_env.hpp>
15 :
16 : #include <type_traits>
17 :
18 : namespace boost {
19 : namespace capy {
20 : namespace detail {
21 :
22 : // Helper to normalize await_suspend return types to std::coroutine_handle<>
23 : template<typename Awaitable>
24 7 : std::coroutine_handle<> call_await_suspend(
25 : Awaitable* a,
26 : std::coroutine_handle<> h,
27 : io_env const* env)
28 : {
29 : using R = decltype(a->await_suspend(h, env));
30 : if constexpr (std::is_void_v<R>)
31 : {
32 0 : a->await_suspend(h, env);
33 0 : return std::noop_coroutine();
34 : }
35 : else if constexpr (std::is_same_v<R, bool>)
36 : {
37 : if(a->await_suspend(h, env))
38 : return std::noop_coroutine();
39 : return h;
40 : }
41 : else
42 : {
43 7 : return a->await_suspend(h, env);
44 : }
45 : }
46 :
47 : } // namespace detail
48 : } // namespace capy
49 : } // namespace boost
50 :
51 : #endif
|