-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompletableCoroutine.h
More file actions
65 lines (39 loc) · 1.34 KB
/
CompletableCoroutine.h
File metadata and controls
65 lines (39 loc) · 1.34 KB
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
64
65
#pragma once
#include <experimental\coroutine>
#include <iostream>
#include <string>
#include <thread>
#include <chrono>
#include "VoidCoroutine.h"
using namespace std;
using namespace std::experimental;
using namespace std::chrono_literals;
class CompletableCoroutine {
public:
struct promise_type {
CompletableCoroutine get_return_object();
auto initial_suspend();
auto final_suspend();
void return_void();
};
std::experimental::coroutine_handle<promise_type> _coroutine = nullptr;
explicit CompletableCoroutine(std::experimental::coroutine_handle<promise_type> coroutine);
~CompletableCoroutine();
CompletableCoroutine() = default;
CompletableCoroutine(CompletableCoroutine const&) = delete;
CompletableCoroutine& operator=(CompletableCoroutine const&) = delete;
CompletableCoroutine(CompletableCoroutine&& other);
CompletableCoroutine& operator=(CompletableCoroutine&& other);
struct awaiter;
awaiter operator co_await() noexcept;
void complete();
struct awaiter {
CompletableCoroutine& m_resumable;
awaiter(CompletableCoroutine& resumable) noexcept;
bool await_ready();
void await_resume();
void await_suspend(coroutine_handle<> waitingCoroutine);
};
private:
coroutine_handle<> m_waitingCoroutine;
};