-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvs19.cpp
More file actions
35 lines (28 loc) · 847 Bytes
/
vs19.cpp
File metadata and controls
35 lines (28 loc) · 847 Bytes
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
#include <iostream>
#include <string>
#include "caf/all.hpp"
#include "caf/io/all.hpp"
using namespace caf;
struct cell_state {
int value = 0;
};
behavior cell(stateful_actor<cell_state>* self) {
return {
[=](get_atom) { return self->state.value; },
[=](put_atom, int x) { self->state.value = x; },
};
}
std::ostream& operator<<(std::ostream& out, const expected<message>& x) {
return out << to_string(x);
}
void caf_main(actor_system& sys) {
auto worker = sys.spawn(cell);
scoped_actor self{sys};
self->send(worker, put_atom_v, 42);
self->request(worker, infinite, get_atom_v)
.receive([&](int value) { std::cout << "cell value: " << value << '\n'; },
[&](const error& err) {
std::cerr << "unable to read cell: " << to_string(err) << '\n';
});
}
CAF_MAIN(io::middleman)