27 constexpr static bool IsVoid =
false;
31 template<
typename U = R>
34 Ret_.emplace (std::forward<U> (val));
53 template<
typename Promise>
56 using Handle_t = std::coroutine_handle<Promise>;
61 const auto& promise =
Handle_.promise ();
62 if (promise.Exception_)
65 if constexpr (Promise::IsVoid)
68 return static_cast<bool> (promise.Ret_);
73 Handle_.promise ().WaitingHandles_.push_back (handle);
78 const auto& promise =
Handle_.promise ();
79 if (promise.Exception_)
82 std::rethrow_exception (promise.Exception_);
88 if constexpr (!Promise::IsVoid)
94 template<
typename R,
template<
typename>
typename... Extensions>
100 using Handle_t = std::coroutine_handle<promise_type>;
104 , Extensions<promise_type>...
110 auto GetAddress () {
return Handle_t::from_promise (*this).address (); }
114 return Task { Handle_t::from_promise (*
this) };
123 using Base = Extensions<promise_type>;
124 if constexpr (
requires (Base t) { t.FinalSuspend (); })
125 Base::FinalSuspend ();
143 Handle_t::from_promise (*this).destroy ();
149 template<
typename RR>
152 explicit Task (
const std::coroutine_handle<promise_type>& handle)
156 handle.promise ().IncRef ();
162 Handle_.promise ().DecRef ();
166 : Handle_ { other.Handle_ }
169 Handle_.promise ().IncRef ();
175 *
this = std::move (task);
181 std::swap (Handle_, other.Handle_);
186 std::swap (Handle_, other.Handle_);
190 auto operator co_await ()
const noexcept
198 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