File indexing completed on 2025-02-24 09:42:59
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_COBALT_DETAIL_DETACHED_HPP
0009 #define BOOST_COBALT_DETAIL_DETACHED_HPP
0010
0011 #include <boost/cobalt/detail/exception.hpp>
0012 #include <boost/cobalt/detail/forward_cancellation.hpp>
0013 #include <boost/cobalt/detail/wrapper.hpp>
0014 #include <boost/cobalt/detail/this_thread.hpp>
0015
0016 #include <boost/asio/cancellation_signal.hpp>
0017
0018
0019
0020
0021 #include <boost/core/exchange.hpp>
0022
0023 #include <coroutine>
0024 #include <optional>
0025 #include <utility>
0026 #include <boost/asio/bind_allocator.hpp>
0027
0028 namespace boost::cobalt
0029 {
0030
0031 struct detached;
0032
0033 namespace detail
0034 {
0035
0036 struct detached_promise
0037 : promise_memory_resource_base,
0038 promise_cancellation_base<asio::cancellation_slot, asio::enable_total_cancellation>,
0039 promise_throw_if_cancelled_base,
0040 enable_awaitables<detached_promise>,
0041 enable_await_allocator<detached_promise>,
0042 enable_await_executor<detached_promise>
0043 {
0044 using promise_cancellation_base<asio::cancellation_slot, asio::enable_total_cancellation>::await_transform;
0045 using promise_throw_if_cancelled_base::await_transform;
0046 using enable_awaitables<detached_promise>::await_transform;
0047 using enable_await_allocator<detached_promise>::await_transform;
0048 using enable_await_executor<detached_promise>::await_transform;
0049
0050 [[nodiscard]] detached get_return_object();
0051
0052 std::suspend_never await_transform(
0053 cobalt::this_coro::reset_cancellation_source_t<asio::cancellation_slot> reset) noexcept
0054 {
0055 this->reset_cancellation_source(reset.source);
0056 return {};
0057 }
0058
0059 using executor_type = executor;
0060 executor_type exec;
0061 const executor_type & get_executor() const {return exec;}
0062
0063 template<typename ... Args>
0064 detached_promise(Args & ...args)
0065 :
0066 #if !defined(BOOST_COBALT_NO_PMR)
0067 promise_memory_resource_base(detail::get_memory_resource_from_args(args...)),
0068 #endif
0069 exec{detail::get_executor_from_args(args...)}
0070 {
0071 }
0072
0073 std::suspend_never initial_suspend() {return {};}
0074 std::suspend_never final_suspend() noexcept {return {};}
0075
0076 void return_void() {}
0077 void unhandled_exception()
0078 {
0079 throw ;
0080 }
0081 };
0082
0083 }
0084
0085 }
0086
0087 #endif