I have a very simple coroutine example to understand basics. However, I am stuck to understand why the done method of the handle object still returns false. I call resume and there is no more co_await though. What am I missing here?
#include <coroutine>
#include <iostream>
struct ReturnObject {
struct promise_type {
ReturnObject get_return_object() {
return {std::coroutine_handle<promise_type>::from_promise(*this)};
}
std::suspend_never initial_suspend() noexcept { return {}; }
std::suspend_never final_suspend() noexcept { return {}; }
void unhandled_exception() {}
void return_void() noexcept {}
};
ReturnObject(std::coroutine_handle<> h) : h_{h}{ }
std::coroutine_handle<> h_;
};
ReturnObject foo() {
std::cout << "1. Hello World!\n";
co_await std::suspend_always{};
std::cout << "2. Hello World!\n";
}
int main(int argc, char** argv) {
ReturnObject ret_object = foo();
ret_object.h_();
std::cout << ret_object.h_.done() << std::endl;
return 0;
}
I call resume and there is no more co_await though but done method always still returns false