-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_value.cpp
More file actions
54 lines (41 loc) · 1.35 KB
/
get_value.cpp
File metadata and controls
54 lines (41 loc) · 1.35 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
/*
* 从无栈协程的外部获取不同类型数据
*/
#include "coroutine_utils.hpp"
#include <iostream>
class worker : public coroutine_base {
public:
worker() {
// run to first yield
(*this)(0);
}
template<class T>
void operator()(T input) {
COROUTINE_BEGIN
std::cout << "waiting input for task 1..." << std::endl;
COROUTINE_YIELD();
std::cout << "task 1, get input of [type: " << typeid(T).name() << " value:" << input << "]" << std::endl;
std::cout << "waiting input for task 2..." << std::endl;
COROUTINE_YIELD();
std::cout << "task 2, get input of [type: " << typeid(T).name() << " value:" << input << "]" << std::endl;
std::cout << "waiting input for task 3..." << std::endl;
COROUTINE_YIELD();
std::cout << "task 3, get input of [type: " << typeid(T).name() << " value:" << input << "]" << std::endl;
std::cout << "waiting input for task 4..." << std::endl;
COROUTINE_YIELD();
std::cout << "task 4, get input of [type: " << typeid(T).name() << " value:" << input << "]" << std::endl;
COROUTINE_RETURN();
COROUTINE_END
}
};
int main() {
auto w = worker();
// do something...
w(1);
// do something...
w(2.);
// do something...
w("3");
// do something...
w('4');
}