-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathio_multiplex.cpp
38 lines (32 loc) · 899 Bytes
/
io_multiplex.cpp
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
#include <co_async/std.hpp>
#include <co_async/co_async.hpp>
#include <co_async/utils/debug.hpp>
using namespace co_async;
using namespace std;
static Queue<char> q1(1);
static Queue<char> q2(1);
[[maybe_unused]] static Task<Expected<>> task1() {
while (true) {
char c = co_await co_await raw_stdio().getchar();
co_await co_await q1.push(std::move(c));
}
}
[[maybe_unused]] static Task<Expected<>> task2() {
auto f = co_await co_await file_open("/dev/input/mouse0", OpenMode::Read);
while (true) {
char c = co_await co_await f.getchar();
co_await co_await q2.push(std::move(c));
}
}
static Task<Expected<>> amain() {
co_spawn(task1());
co_spawn(task2());
while (true) {
auto r = co_await (co_await when_any_common(q1.pop(), q2.pop())).value;
debug(), r;
}
}
int main() {
co_main(amain());
return 0;
}