26 constexpr static bool IsVoid =
false;
30 template<
typename U = R>
33 Ret_.emplace (std::forward<U> (val));
52 template<
typename Promise>
55 using Handle_t = std::coroutine_handle<Promise>;
60 const auto& promise =
Handle_.promise ();
61 if (promise.Exception_)
64 if constexpr (Promise::IsVoid)
67 return static_cast<bool> (promise.Ret_);
72 Handle_.promise ().WaitingHandles_.push_back (handle);
77 const auto& promise =
Handle_.promise ();
78 if (promise.Exception_)
81 std::rethrow_exception (promise.Exception_);
87 if constexpr (!Promise::IsVoid)
93 template<
typename R,
template<
typename>
typename... Extensions>
99 using Handle_t = std::coroutine_handle<promise_type>;
103 , Extensions<promise_type>...
109 auto GetAddress () {
return Handle_t::from_promise (*this).address (); }
113 return Task { Handle_t::from_promise (*
this) };
122 using Base = Extensions<promise_type>;
123 if constexpr (
requires (Base t) { t.FinalSuspend (); })
124 Base::FinalSuspend ();
142 Handle_t::from_promise (*this).destroy ();
148 template<
typename RR>
151 explicit Task (
const std::coroutine_handle<promise_type>& handle)
155 handle.promise ().IncRef ();
161 Handle_.promise ().DecRef ();
165 : Handle_ { other.Handle_ }
168 Handle_.promise ().IncRef ();
174 *
this = std::move (task);
180 std::swap (Handle_, other.Handle_);
185 std::swap (Handle_, other.Handle_);
189 auto operator co_await ()
const noexcept
197 template<
typename R,
template<
typename>
typename... Extensions>
Task & operator=(const Task &other)
Task(Task &&other) noexcept
Task< RR, Extensions... > ReplaceResult_t
Task(const std::coroutine_handle< promise_type > &handle)
std::suspend_never initial_suspend() const noexcept
auto final_suspend() noexcept
QVector< std::coroutine_handle<> > WaitingHandles_
void unhandled_exception()
std::exception_ptr Exception_
bool await_ready() const noexcept
decltype(auto) await_resume() const noexcept
bool await_suspend(std::coroutine_handle< Promise > handle) const noexcept
typename Task< R, Extensions... >::promise_type Promise
static constexpr bool IsVoid
void return_void() noexcept
static constexpr bool IsVoid
void return_value(U &&val)
bool await_ready() const noexcept
std::coroutine_handle< Promise > Handle_t
void await_suspend(std::coroutine_handle<> handle)
auto await_resume() const