18 #include <experimental/coroutine> 20 #include <type_traits> 44 return static_cast<T&&
>(
value_);
62 template <
typename Awaitable>
66 std::is_same<Awaitable, std::decay_t<Awaitable>>::
value,
67 "Awaitable should be decayed.");
71 : awaitable_(
std::
move(awaitable)), duration_(duration) {}
78 auto sharedState = std::make_shared<SharedState>(
ch, storage_);
79 waitAndNotify(
std::move(awaitable_), sharedState).detach();
82 sharedState->setTimeout();
88 if (!storage_.hasValue() && !storage_.hasException()) {
98 std::experimental::coroutine_handle<>
ch,
100 : ch_(
std::
move(ch)), storage_(storage) {}
103 if (first_.exchange(
true, std::memory_order_relaxed)) {
106 assume(!storage_.hasValue() && !storage_.hasException());
112 if (first_.exchange(
true, std::memory_order_relaxed)) {
115 assume(!storage_.hasValue() && !storage_.hasException());
121 if (first_.exchange(
true, std::memory_order_relaxed)) {
128 std::atomic<bool> first_{
false};
129 std::experimental::coroutine_handle<>
ch_;
135 std::shared_ptr<SharedState> sharedState) {
137 sharedState->setValue(co_await std::forward<Awaitable>(awaitable));
138 }
catch (
const std::exception& e) {
150 template <
typename Awaitable>
152 Awaitable&& awaitable,
153 std::chrono::milliseconds duration) {
155 std::forward<Awaitable>(awaitable), duration);
await_result_t< Awaitable > await_resume_return_type
T * tryEmplace(Try< T > &t, Args &&...args) noexcept
void await_resume() noexcept
void await_suspend(std::experimental::coroutine_handle<>) noexcept
T await_resume() noexcept(std::is_nothrow_move_constructible< T >::value)
std::experimental::coroutine_handle ch_
bool await_ready() noexcept
void setException(exception_wrapper e)
Future< Unit > sleep(Duration dur, Timekeeper *tk)
constexpr detail::Map< Move > move
AwaitableReady(T value) noexcept(std::is_nothrow_move_constructible< T >::value)
Optional< await_resume_return_type > await_resume()
—— Concurrent Priority Queue Implementation ——
bool await_ready() noexcept
SharedState(std::experimental::coroutine_handle<> ch, Try< await_resume_return_type > &storage)
TimedWaitAwaitable< std::decay_t< Awaitable > > timed_wait(Awaitable &&awaitable, std::chrono::milliseconds duration)
requires E e noexcept(noexcept(s.error(std::move(e))))
typename await_result< Awaitable >::type await_result_t
std::chrono::milliseconds duration_
void setValue(await_resume_return_type &&value)
static const char *const value
TimedWaitAwaitable(Awaitable &&awaitable, std::chrono::milliseconds duration)
Try< await_resume_return_type > & storage_
void await_suspend(std::experimental::coroutine_handle<>) noexcept
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
Try< await_resume_return_type > storage_
FOLLY_ALWAYS_INLINE void assume(bool cond)
static Wait waitAndNotify(Awaitable awaitable, std::shared_ptr< SharedState > sharedState)
bool await_suspend(std::experimental::coroutine_handle<> ch)