File indexing completed on 2025-01-30 09:34:30
0001
0002
0003
0004
0005 #ifndef BOOST_COBALT_DETAIL_LEAF_HPP
0006 #define BOOST_COBALT_DETAIL_LEAF_HPP
0007
0008 #include <boost/cobalt/detail/await_result_helper.hpp>
0009 #include <boost/leaf/config.hpp>
0010 #include <boost/leaf/capture.hpp>
0011 #include <boost/leaf/handle_errors.hpp>
0012
0013 namespace boost::cobalt::detail
0014 {
0015
0016 template<typename Awaitable, typename ... H>
0017 struct [[nodiscard]] try_catch_awaitable
0018 {
0019 Awaitable aw;
0020 std::tuple<H...> handler;
0021
0022 bool await_ready() {return aw.await_ready(); }
0023 template<typename Promise>
0024 auto await_suspend(std::coroutine_handle<Promise> h) {return aw.await_suspend(h);}
0025
0026 auto await_resume()
0027 {
0028 return std::apply(
0029 [this](auto && ... h)
0030 {
0031 return leaf::try_catch(
0032 [this]{return std::move(aw).await_resume();},
0033 std::move(h)...);
0034 }, std::move(handler));
0035 }
0036 };
0037
0038 template<typename Awaitable, typename ... H>
0039 struct [[nodiscard]] try_handle_all_awaitable
0040 {
0041 Awaitable aw;
0042 std::tuple<H...> handler;
0043
0044 bool await_ready() {return aw.await_ready(); }
0045 template<typename Promise>
0046 auto await_suspend(std::coroutine_handle<Promise> h) {return aw.await_suspend(h);}
0047
0048 auto await_resume()
0049 {
0050 return std::apply(
0051 [this](auto && ... h)
0052 {
0053 return leaf::try_handle_all(
0054 [this]{return std::move(aw).await_resume();},
0055 std::move(h)...);
0056 }, std::move(handler));
0057 }
0058 };
0059
0060
0061
0062 template<typename Awaitable, typename ... H>
0063 struct [[nodiscard]] try_handle_some_awaitable
0064 {
0065 Awaitable aw;
0066 std::tuple<H...> handler;
0067
0068 bool await_ready() {return aw.await_ready(); }
0069 template<typename Promise>
0070 auto await_suspend(std::coroutine_handle<Promise> h) {return aw.await_suspend(h);}
0071
0072 auto await_resume()
0073 {
0074 return std::apply(
0075 [this](auto && ... h)
0076 {
0077 return leaf::try_handle_some(
0078 [this]{return std::move(aw).await_resume();},
0079 std::move(h)...);
0080 }, std::move(handler));
0081 }
0082 };
0083
0084 }
0085
0086 #endif