| 1 |
#include <coroutine> |
| 2 |
|
| 3 |
struct promise_type; |
| 4 |
using handle_type = std::coroutine_handle<promise_type>; |
| 5 |
|
| 6 |
struct Co { |
| 7 |
handle_type handle; |
| 8 |
using promise_type = ::promise_type; |
| 9 |
|
| 10 |
explicit Co(handle_type handle) : handle(handle) {} |
| 11 |
|
| 12 |
bool await_ready() { return false; } |
| 13 |
std::coroutine_handle<> await_suspend(handle_type handle); |
| 14 |
void await_resume() {} |
| 15 |
}; |
| 16 |
|
| 17 |
struct Done {}; |
| 18 |
|
| 19 |
struct promise_type { |
| 20 |
Co get_return_object(); |
| 21 |
|
| 22 |
std::suspend_always initial_suspend() { return {}; }; |
| 23 |
std::suspend_always final_suspend() noexcept { return {}; }; |
| 24 |
void return_value(Done) {} |
| 25 |
void return_value(Co&&); |
| 26 |
void unhandled_exception() { throw; }; |
| 27 |
Co&& await_transform(Co&& co) { return static_cast<Co&&>(co); } |
| 28 |
}; |
| 29 |
|
| 30 |
Co tryToRun(); |
| 31 |
|
| 32 |
Co init() |
| 33 |
{ |
| 34 |
co_await tryToRun(); |
| 35 |
co_return Done{}; |
| 36 |
} |