-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompletableCoroutine.cpp
More file actions
64 lines (45 loc) · 1.84 KB
/
CompletableCoroutine.cpp
File metadata and controls
64 lines (45 loc) · 1.84 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
#include "stdafx.h"
#include "CompletableCoroutine.h"
CompletableCoroutine CompletableCoroutine::promise_type::get_return_object() {
return CompletableCoroutine(std::experimental::coroutine_handle<promise_type>::from_promise(*this));
}
auto CompletableCoroutine::promise_type::initial_suspend() { return std::experimental::suspend_never{}; }
auto CompletableCoroutine::promise_type::final_suspend() { return std::experimental::suspend_never{}; }
void CompletableCoroutine::promise_type::return_void() {};
CompletableCoroutine::CompletableCoroutine(std::experimental::coroutine_handle<promise_type> coroutine)
: _coroutine(coroutine) {}
CompletableCoroutine::~CompletableCoroutine() {
if (_coroutine) { _coroutine.destroy(); }
}
CompletableCoroutine::CompletableCoroutine(CompletableCoroutine&& other)
:_coroutine(other._coroutine) {
other._coroutine = nullptr;
}
CompletableCoroutine& CompletableCoroutine::operator=(CompletableCoroutine&& other) {
if (&other != this) {
_coroutine = other._coroutine;
other._coroutine = nullptr;
}
return *this;
}
CompletableCoroutine::awaiter::awaiter(CompletableCoroutine& resumable) noexcept
:m_resumable(resumable) {
}
bool CompletableCoroutine::awaiter::await_ready() {
cout << "CompletableCoroutine::await_ready\n";
return false;
}
void CompletableCoroutine::awaiter::await_resume() {
cout << "CompletableCoroutine::await_resume\n";
}
void CompletableCoroutine::awaiter::await_suspend(coroutine_handle<> waitingCoroutine) {
cout << "CompletableCoroutine::await_suspend\n";
m_resumable.m_waitingCoroutine = waitingCoroutine;
}
CompletableCoroutine::awaiter CompletableCoroutine::operator co_await() noexcept {
awaiter returnObject = awaiter{ *this };
return returnObject;
}
void CompletableCoroutine::complete() {
m_waitingCoroutine.resume();
}