File indexing completed on 2025-07-09 08:06:02
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 #include <boost/cobalt/op.hpp>
0016
0017 #include <boost/asio/cancellation_signal.hpp>
0018
0019 #include <boost/core/exchange.hpp>
0020
0021 #include <coroutine>
0022 #include <optional>
0023 #include <utility>
0024 #include <boost/asio/bind_allocator.hpp>
0025
0026 namespace boost::cobalt
0027 {
0028
0029 struct detached;
0030
0031 namespace detail
0032 {
0033
0034 struct detached_promise
0035 : promise_memory_resource_base,
0036 promise_cancellation_base<asio::cancellation_slot, asio::enable_total_cancellation>,
0037 promise_throw_if_cancelled_base,
0038 enable_awaitables<detached_promise>,
0039 enable_await_allocator<detached_promise>,
0040 enable_await_executor<detached_promise>,
0041 enable_await_deferred
0042 {
0043 using promise_cancellation_base<asio::cancellation_slot, asio::enable_total_cancellation>::await_transform;
0044 using promise_throw_if_cancelled_base::await_transform;
0045 using enable_awaitables<detached_promise>::await_transform;
0046 using enable_await_allocator<detached_promise>::await_transform;
0047 using enable_await_executor<detached_promise>::await_transform;
0048 using enable_await_deferred::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() noexcept {return {};}
0074 std::suspend_never final_suspend() noexcept {return {};}
0075
0076 void return_void() {}
0077 #if !defined(BOOST_NO_EXCEPTIONS)
0078 void unhandled_exception() { throw ; }
0079 #endif
0080 };
0081
0082 }
0083
0084 }
0085
0086 #endif