5 // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_ASIO_AWAITABLE_HPP
12 #define BOOST_ASIO_AWAITABLE_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
20 #if defined(BOOST_ASIO_HAS_CO_AWAIT) || defined(GENERATING_DOCUMENTATION)
22 #include <experimental/coroutine>
23 #include <boost/asio/executor.hpp>
25 #include <boost/asio/detail/push_options.hpp>
31 using std::experimental::coroutine_handle;
32 using std::experimental::suspend_always;
34 template <typename> class awaitable_thread;
35 template <typename, typename> class awaitable_frame;
39 /// The return type of a coroutine or asynchronous operation.
40 template <typename T, typename Executor = executor>
44 /// The type of the awaited value.
47 /// The executor type that will be used for the coroutine.
48 typedef Executor executor_type;
50 /// Default constructor.
51 constexpr awaitable() noexcept
57 awaitable(awaitable&& other) noexcept
58 : frame_(std::exchange(other.frame_, nullptr))
69 /// Checks if the awaitable refers to a future result.
70 bool valid() const noexcept
75 #if !defined(GENERATING_DOCUMENTATION)
77 // Support for co_await keyword.
78 bool await_ready() const noexcept
83 // Support for co_await keyword.
86 detail::coroutine_handle<detail::awaitable_frame<U, Executor>> h)
88 frame_->push_frame(&h.promise());
91 // Support for co_await keyword.
97 #endif // !defined(GENERATING_DOCUMENTATION)
100 template <typename> friend class detail::awaitable_thread;
101 template <typename, typename> friend class detail::awaitable_frame;
103 // Not copy constructible or copy assignable.
104 awaitable(const awaitable&) = delete;
105 awaitable& operator=(const awaitable&) = delete;
107 // Construct the awaitable from a coroutine's frame object.
108 explicit awaitable(detail::awaitable_frame<T, Executor>* a)
113 detail::awaitable_frame<T, Executor>* frame_;
119 #include <boost/asio/detail/pop_options.hpp>
121 #include <boost/asio/impl/awaitable.hpp>
123 #endif // defined(BOOST_ASIO_HAS_CO_AWAIT) || defined(GENERATING_DOCUMENTATION)
125 #endif // BOOST_ASIO_AWAITABLE_HPP