librf
yield.h
1 #pragma once
2 
3 namespace resumef
4 {
8  struct yield_awaitor
9  {
10  using value_type = void;
12  using promise_type = promise_t<value_type>;
13  using lock_type = typename state_type::lock_type;
14 
15  bool await_ready() const noexcept
16  {
17  return false;
18  }
19  template<class _PromiseT, typename = std::enable_if_t<traits::is_promise_v<_PromiseT>>>
20  bool await_suspend(coroutine_handle<_PromiseT> handler)
21  {
22  counted_ptr<state_t<void>> _state = state_future_t::_Alloc_state<state_type>(true);
23  _state->set_value();
24  _state->future_await_suspend(handler);
25 
26  return true;
27  }
28  void await_resume() const noexcept
29  {
30  }
31 
32 #ifdef DOXYGEN_SKIP_PROPERTY
33 
38  static yield_awaitor yield() noexcept;
39 #endif //DOXYGEN_SKIP_PROPERTY
40  };
41 
46  inline yield_awaitor yield() noexcept
47  {
48  return {};
49  }
50 
51 }
resumef::yield_awaitor
将本协程让渡出一次调用的可等待对象。
Definition: yield.h:8
resumef::counted_ptr
专用与state的智能计数指针,通过管理state内嵌的引用计数来管理state的生存期。
Definition: counted_ptr.h:9
resumef::spinlock
一个自旋锁实现。
Definition: spinlock.h:14
resumef::state_t
专用于future_t<>的state类。
Definition: state.h:217
resumef::yield_awaitor::yield
static yield_awaitor yield() noexcept
将本协程让渡出一次调用的可等待对象。