18 #include <experimental/coroutine> 19 #include <type_traits> 21 #include <glog/logging.h> 37 template <
typename T =
void>
40 template <
typename T =
void>
52 template <
typename Promise>
54 std::experimental::coroutine_handle<Promise> coro)
noexcept {
79 template <
typename Awaitable>
82 return co_viaIfAsync(executor_, static_cast<Awaitable&&>(awaitable));
100 template <
typename T>
108 result_.emplaceException(
112 template <
typename U>
116 "cannot convert return value to type T");
117 result_.emplace(static_cast<U&&>(
value));
121 return static_cast<T&&
>(
std::move(result_).value());
127 std::reference_wrapper<std::remove_reference_t<T>>,
141 result_.emplaceException(
163 template <
typename T>
165 using handle_t = std::experimental::coroutine_handle<detail::TaskPromise<T>>;
183 return coro_.promise().executor_;
193 return folly::coro::toSemiFuture(
std::move(*
this));
211 std::experimental::coroutine_handle<> continuation)
noexcept {
212 auto& promise = coro_.promise();
213 DCHECK(!promise.continuation_);
214 DCHECK(promise.executor_ !=
nullptr);
216 promise.continuation_ = continuation;
217 promise.executor_->add(coro_);
220 decltype(
auto) await_resume() {
225 return coro_.promise().getResult();
261 template <
typename T>
267 using handle_t = std::experimental::coroutine_handle<promise_type>;
295 coro_.promise().executor_ =
executor;
308 template <
typename T>
312 std::experimental::coroutine_handle<detail::TaskPromise<T>>;
315 explicit Awaiter(handle_t coro) noexcept : coro_(coro) {}
317 Awaiter(Awaiter&& other) noexcept : coro_(
std::exchange(other.coro_, {})) {}
319 Awaiter(
const Awaiter&) =
delete;
327 bool await_ready() noexcept {
331 handle_t await_suspend(
332 std::experimental::coroutine_handle<> continuation) noexcept {
333 coro_.promise().continuation_ = continuation;
337 decltype(
auto) await_resume() {
341 return coro_.promise().getResult();
348 t.coro_.promise().executor_ = executor_;
352 template <
typename T>
355 std::experimental::coroutine_handle<detail::TaskPromise<T>>::from_promise(
360 return Task<void>{std::experimental::coroutine_handle<
void swap(Task &t) noexcept
TaskWithExecutor(handle_t coro) noexcept
void await_resume() noexcept
std::experimental::coroutine_handle continuation_
auto await_transform(Task< U > &&t) noexcept
std::experimental::coroutine_handle< detail::TaskPromise< T >> handle_t
void unhandled_exception() noexcept
FinalAwaiter final_suspend() noexcept
void await_suspend(std::experimental::coroutine_handle<> continuation) noexcept
void return_value(U &&value)
constexpr detail::Map< Move > move
auto co_viaIfAsync(folly::Executor *executor, Awaitable &&awaitable) -> ViaIfAsyncAwaitable< Awaitable >
static exception_wrapper from_exception_ptr(std::exception_ptr const &eptr) noexcept
std::experimental::coroutine_handle< promise_type > handle_t
—— Concurrent Priority Queue Implementation ——
auto await_transform(Awaitable &&awaitable) noexcept
requires E e noexcept(noexcept(s.error(std::move(e))))
TaskPromiseBase() noexcept
PUSHMI_INLINE_VAR constexpr __adl::get_executor_fn executor
void return_void() noexcept
std::conditional_t< std::is_reference< T >::value, std::reference_wrapper< std::remove_reference_t< T >>, T > StorageType
folly::Executor * executor_
Try< StorageType > result_
FOLLY_NODISCARD TaskWithExecutor< T > scheduleOn(Executor *executor)&&noexcept
folly::Executor * executor() const noexcept
static const char *const value
std::experimental::coroutine_handle await_suspend(std::experimental::coroutine_handle< Promise > coro) noexcept
TaskWithExecutor(TaskWithExecutor &&t) noexcept
Task & operator=(Task t) noexcept
void swap(exception_wrapper &a, exception_wrapper &b) noexcept
T exchange(T &obj, U &&new_value)
TaskWithExecutor & operator=(TaskWithExecutor t) noexcept
auto await_transform(folly::coro::getCurrentExecutor) noexcept
bool await_ready() noexcept
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
Task< T > get_return_object() noexcept
void unhandled_exception() noexcept
void swap(SwapTrackingAlloc< T > &, SwapTrackingAlloc< T > &)
Awaiter(handle_t coro) noexcept
Task(handle_t coro) noexcept
void swap(TaskWithExecutor &t) noexcept
std::experimental::suspend_always initial_suspend() noexcept