librf
future.h
1 
2 #pragma once
3 
4 namespace resumef
5 {
6 
13  template<class _Ty>
14  struct [[nodiscard]] future_t
15  {
16  using value_type = _Ty;
18  using promise_type = promise_t<value_type>;
20  using lock_type = typename state_type::lock_type;
21 
23 
24  future_t(counted_ptr<state_type> _st) noexcept
25  :_state(std::move(_st)) {}
26  future_t(const future_t&) = default;
27  future_t(future_t&&) = default;
28 
29  future_t& operator = (const future_t&) = default;
30  future_t& operator = (future_t&&) = default;
31 
32  bool await_ready() noexcept
33  {
34  return _state->future_await_ready();
35  }
36 
37  template<class _PromiseT, typename = std::enable_if_t<traits::is_promise_v<_PromiseT>>>
38  void await_suspend(coroutine_handle<_PromiseT> handler)
39  {
40  _state->future_await_suspend(handler);
41  }
42 
43  value_type await_resume()
44  {
45  return _state->future_await_resume();
46  }
47  };
48 }
49 
50 #ifndef DOXYGEN_SKIP_PROPERTY
51 namespace std {
52  namespace experimental {
53 
54  /*If the coroutine is defined as task<float> foo(std::string x, bool flag);,
55  then its Promise type is std::coroutine_traits<task<float>, std::string, bool>::promise_type.
56  If the coroutine is a non-static member function, such as task<void> my_class::method1(int x) const;,
57  its Promise type is std::coroutine_traits<task<void>, const my_class&, int>::promise_type.
58  */
59  template <typename _Ty, typename... Args>
60  struct coroutine_traits<resumef::future_t<_Ty>, Args...>
61  {
62  typedef resumef::promise_t<_Ty> promise_type;
63  };
64  }
65 } // namespace std::experimental
66 #endif //DOXYGEN_SKIP_PROPERTY
resumef::future_t
用于resumef协程的返回值。
Definition: future.h:14
resumef::counted_ptr< state_type >
resumef::spinlock
一个自旋锁实现。
Definition: spinlock.h:14
resumef::state_t
专用于future_t<>的state类。
Definition: state.h:217