proxygen
folly::coro::TimedWaitAwaitable< Awaitable > Class Template Reference

#include <Utils.h>

Classes

class  SharedState
 

Public Types

using await_resume_return_type = await_result_t< Awaitable >
 

Public Member Functions

 TimedWaitAwaitable (Awaitable &&awaitable, std::chrono::milliseconds duration)
 
bool await_ready ()
 
bool await_suspend (std::experimental::coroutine_handle<> ch)
 
Optional< await_resume_return_typeawait_resume ()
 

Static Private Member Functions

static Wait waitAndNotify (Awaitable awaitable, std::shared_ptr< SharedState > sharedState)
 

Private Attributes

Awaitable awaitable_
 
std::chrono::milliseconds duration_
 
Try< await_resume_return_typestorage_
 

Detailed Description

template<typename Awaitable>
class folly::coro::TimedWaitAwaitable< Awaitable >

Definition at line 63 of file Utils.h.

Member Typedef Documentation

template<typename Awaitable >
using folly::coro::TimedWaitAwaitable< Awaitable >::await_resume_return_type = await_result_t<Awaitable>

Definition at line 68 of file Utils.h.

Constructor & Destructor Documentation

template<typename Awaitable >
folly::coro::TimedWaitAwaitable< Awaitable >::TimedWaitAwaitable ( Awaitable &&  awaitable,
std::chrono::milliseconds  duration 
)
inline

Definition at line 70 of file Utils.h.

71  : awaitable_(std::move(awaitable)), duration_(duration) {}
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::chrono::milliseconds duration_
Definition: Utils.h:146

Member Function Documentation

template<typename Awaitable >
bool folly::coro::TimedWaitAwaitable< Awaitable >::await_ready ( )
inline

Definition at line 73 of file Utils.h.

73  {
74  return false;
75  }
template<typename Awaitable >
Optional<await_resume_return_type> folly::coro::TimedWaitAwaitable< Awaitable >::await_resume ( )
inline

Definition at line 87 of file Utils.h.

References folly::gen::move, and folly::none.

87  {
88  if (!storage_.hasValue() && !storage_.hasException()) {
89  return folly::none;
90  }
91  return std::move(storage_).value();
92  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
bool hasException() const
Definition: Try.h:248
bool hasValue() const
Definition: Try.h:242
Try< await_resume_return_type > storage_
Definition: Utils.h:147
constexpr None none
Definition: Optional.h:87
template<typename Awaitable >
bool folly::coro::TimedWaitAwaitable< Awaitable >::await_suspend ( std::experimental::coroutine_handle<>  ch)
inline

Definition at line 77 of file Utils.h.

References ch, folly::gen::move, and folly::futures::sleep().

77  {
78  auto sharedState = std::make_shared<SharedState>(ch, storage_);
79  waitAndNotify(std::move(awaitable_), sharedState).detach();
80  futures::sleep(duration_).thenValue(
81  [sharedState = std::move(sharedState)](Unit) {
82  sharedState->setTimeout();
83  });
84  return true;
85  }
void detach()
Definition: Wait.h:56
Future< Unit > sleep(Duration dur, Timekeeper *tk)
Definition: Future.cpp:42
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
auto ch
std::chrono::milliseconds duration_
Definition: Utils.h:146
Try< await_resume_return_type > storage_
Definition: Utils.h:147
static Wait waitAndNotify(Awaitable awaitable, std::shared_ptr< SharedState > sharedState)
Definition: Utils.h:133
template<typename Awaitable >
static Wait folly::coro::TimedWaitAwaitable< Awaitable >::waitAndNotify ( Awaitable  awaitable,
std::shared_ptr< SharedState sharedState 
)
inlinestaticprivate

Definition at line 133 of file Utils.h.

135  {
136  try {
137  sharedState->setValue(co_await std::forward<Awaitable>(awaitable));
138  } catch (const std::exception& e) {
139  sharedState->setException(exception_wrapper(std::current_exception(), e));
140  } catch (...) {
141  sharedState->setException(exception_wrapper(std::current_exception()));
142  }
143  }

Member Data Documentation

template<typename Awaitable >
Awaitable folly::coro::TimedWaitAwaitable< Awaitable >::awaitable_
private

Definition at line 145 of file Utils.h.

template<typename Awaitable >
std::chrono::milliseconds folly::coro::TimedWaitAwaitable< Awaitable >::duration_
private

Definition at line 146 of file Utils.h.

template<typename Awaitable >
Try<await_resume_return_type> folly::coro::TimedWaitAwaitable< Awaitable >::storage_
private

Definition at line 147 of file Utils.h.


The documentation for this class was generated from the following file: