123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- #ifndef BOOST_ASIO_AWAITABLE_HPP
- #define BOOST_ASIO_AWAITABLE_HPP
- #if defined(_MSC_VER) && (_MSC_VER >= 1200)
- # pragma once
- #endif
- #include <boost/asio/detail/config.hpp>
- #if defined(BOOST_ASIO_HAS_CO_AWAIT) || defined(GENERATING_DOCUMENTATION)
- #if defined(BOOST_ASIO_HAS_STD_COROUTINE)
- # include <coroutine>
- #else
- # include <experimental/coroutine>
- #endif
- #include <boost/asio/any_io_executor.hpp>
- #include <boost/asio/detail/push_options.hpp>
- namespace boost {
- namespace asio {
- namespace detail {
- #if defined(BOOST_ASIO_HAS_STD_COROUTINE)
- using std::coroutine_handle;
- using std::suspend_always;
- #else
- using std::experimental::coroutine_handle;
- using std::experimental::suspend_always;
- #endif
- template <typename> class awaitable_thread;
- template <typename, typename> class awaitable_frame;
- }
- template <typename T, typename Executor = any_io_executor>
- class awaitable
- {
- public:
-
- typedef T value_type;
-
- typedef Executor executor_type;
-
- constexpr awaitable() noexcept
- : frame_(nullptr)
- {
- }
-
- awaitable(awaitable&& other) noexcept
- : frame_(std::exchange(other.frame_, nullptr))
- {
- }
-
- ~awaitable()
- {
- if (frame_)
- frame_->destroy();
- }
-
- bool valid() const noexcept
- {
- return !!frame_;
- }
- #if !defined(GENERATING_DOCUMENTATION)
-
- bool await_ready() const noexcept
- {
- return false;
- }
-
- template <class U>
- void await_suspend(
- detail::coroutine_handle<detail::awaitable_frame<U, Executor>> h)
- {
- frame_->push_frame(&h.promise());
- }
-
- T await_resume()
- {
- return awaitable(static_cast<awaitable&&>(*this)).frame_->get();
- }
- #endif
- private:
- template <typename> friend class detail::awaitable_thread;
- template <typename, typename> friend class detail::awaitable_frame;
-
- awaitable(const awaitable&) = delete;
- awaitable& operator=(const awaitable&) = delete;
-
- explicit awaitable(detail::awaitable_frame<T, Executor>* a)
- : frame_(a)
- {
- }
- detail::awaitable_frame<T, Executor>* frame_;
- };
- }
- }
- #include <boost/asio/detail/pop_options.hpp>
- #include <boost/asio/impl/awaitable.hpp>
- #endif
- #endif
|