-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoroutinesthings.hpp
42 lines (36 loc) · 1.38 KB
/
coroutinesthings.hpp
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
#include <coroutine>
struct co_getHandle
{
std::coroutine_handle<> _handle;
bool await_ready() const noexcept { return false; }
bool await_suspend(std::coroutine_handle<> handle) noexcept { _handle = handle; return false; }
std::coroutine_handle<> await_resume() noexcept { return _handle; }
};
// ? get handle with promise_type not tested, but it should work!
template <class promise_type>
struct co_getHandle
{
std::coroutine_handle<promise_type> _handle;
bool await_ready() const noexcept { return false; }
bool await_suspend(std::coroutine_handle<promise_type> handle) noexcept { _handle = handle; return false; }
std::coroutine_handle<promise_type> await_resume() noexcept { return _handle; }
};
/*
? if c++23 or if you have tl::expected
#include <expected>
#include <exception>
#include "unittype.h"
using expected_ue = ::expected<Unit,std::exception_ptr>;
template <typename... Args>
struct std::coroutine_traits<expected_ue, Args...> {
struct promise_type {
auto get_return_object() { return std::true_type(); }
std::suspend_never initial_suspend() { return {}; }
std::suspend_never final_suspend() noexcept { return {}; }
void return_void(){}
void unhandled_exception() {
std::rethrow_exception(std::current_exception());
}
};
};
*/