-
Notifications
You must be signed in to change notification settings - Fork 0
/
InternalRunStack.h
63 lines (49 loc) · 1.51 KB
/
InternalRunStack.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once
#include <coroutine>
namespace tk {
namespace internal {
// A void c++20 coroutine that executes a task synchronously until it is
// finished or its not possible to continue execution. Then it co_yield
// the next task to run, or return if there is no next task.
class ExecuteSessionHandle
{
public:
class promise_type
{
struct SuspendAndRun {
std::coroutine_handle<> handle;
constexpr void await_ready() noexcept {}
constexpr std::coroutine_handle<> await_suspend(
std::coroutine_handle<> h) noexcept {
auto toBeRun = handle;
handle = h;
return toBeRun;
}
constexpr void await_resume() noexcept { auto }
};
public:
promise_type() = default;
promise_type(const promise_type&) = delete;
promise_type& operator=(const promise_type&) = delete;
~promise_type() = default;
constexpr std::coroutine_handle<promise_type>
getCoroutine() noexcept {
return std::coroutine_handle<promise_type>::from_promise(
*this);
}
auto get_return_object() { return ExecuteSessionHandle{}; }
constexpr auto initial_suspend() {
return std::suspend_never{};
}
constexpr auto final_suspend() { return std::suspend_always{}; }
constexpr void return_void() {}
static_assert(Promise<promise_type>,
"Something broke and this is no longer a Promise...");
SuspendAndRun<promise_type> yield_value(
ExecuteSessionHandle::promise_type& next) {
return {&next};
}
};
};
}
}