22 Task get_return_object()
noexcept {
23 return Task(std::coroutine_handle<promise_type>::from_promise(*
this));
25 std::suspend_always initial_suspend()
const noexcept {
return {}; }
26 std::suspend_always final_suspend()
const noexcept {
return {}; }
27 void return_void()
const noexcept {}
28 void unhandled_exception()
noexcept { exception = std::current_exception(); }
30 std::exception_ptr exception;
33 Task()
noexcept =
default;
35 Task(
Task&& other) noexcept : handle_(std::exchange(other.handle_, {})) {}
40 handle_ = std::exchange(other.handle_, {});
46 ~Task() { destroy(); }
50 bool done() const noexcept {
return !handle_ || handle_.done(); }
57 return handle_ ? handle_.promise().exception :
nullptr;
61 explicit Task(std::coroutine_handle<promise_type> handle) noexcept : handle_(handle) {}
63 void destroy() noexcept {
64 if (handle_) handle_.destroy();
68 std::coroutine_handle<promise_type> handle_;