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;
17 using state_type = state_t<value_type>;
18 using promise_type = promise_t<value_type>;
19 using future_type = future_t<value_type>;
20 using lock_type = typename state_type::lock_type;
21
22 counted_ptr<state_type> _state;
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 }
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