COROIO: coroio/promises.hpp Source File
COROIO
 
Loading...
Searching...
No Matches
promises.hpp
1#pragma once
2#include <coroutine>
3
4namespace NNet {
5
6struct TVoidPromise;
7
25struct TVoidTask : std::coroutine_handle<TVoidPromise>
26{
28};
29
31{
32 TVoidTask get_return_object() { return { TVoidTask::from_promise(*this) }; }
33 std::suspend_never initial_suspend() { return {}; }
34 std::suspend_never final_suspend() noexcept { return {}; }
35 void return_void() {}
36 void unhandled_exception() {}
37};
38
40
47struct TVoidSuspendedTask : std::coroutine_handle<TVoidSuspendedPromise>
48{
50};
51
53{
54 TVoidSuspendedTask get_return_object() { return { TVoidSuspendedTask::from_promise(*this) }; }
55 std::suspend_never initial_suspend() { return {}; }
56 std::suspend_always final_suspend() noexcept { return {}; }
57 void return_void() {}
58 void unhandled_exception() {}
59};
60
70struct Self {
71 bool await_ready() {
72 return false;
73 }
74
75 bool await_suspend(std::coroutine_handle<> h) {
76 H = h;
77 return false;
78 }
79
80 auto await_resume() noexcept {
81 return H;
82 }
83
84 std::coroutine_handle<> H;
85};
88} // namespace NNet
Definition promises.hpp:31
Definition promises.hpp:53
Like TVoidTask but suspends at final_suspend instead of self-destructing.
Definition promises.hpp:48
Fire-and-forget coroutine handle.
Definition promises.hpp:26