Commit 2e704f7e authored by Dominik Charousset's avatar Dominik Charousset

Fixed typed calculator example

parent 8f2cd321
......@@ -21,14 +21,15 @@ add(. aout)
add(. hello_world)
# basic message passing primitives
add(message_passing cell)
add(message_passing divider)
add(message_passing request)
add(message_passing promises)
add(message_passing calculator)
add(message_passing cell)
add(message_passing dancing_kirby)
add(message_passing delegating)
add(message_passing divider)
add(message_passing fixed_stack)
add(message_passing dancing_kirby)
add(message_passing promises)
add(message_passing request)
add(message_passing typed_calculator)
# dynamic behavior changes using 'become'
add(dynamic_behavior skip_messages)
......
......@@ -32,11 +32,12 @@ calculator_type::behavior_type typed_calculator_fun(calculator_type::pointer) {
}
class typed_calculator_class : public calculator_type::base {
protected:
public:
typed_calculator_class(actor_config& cfg) : calculator_type::base(cfg) {
// nop
}
protected:
behavior_type make_behavior() override {
return {
[](plus_atom, int x, int y) {
......@@ -52,10 +53,10 @@ protected:
void tester(event_based_actor* self, const calculator_type& testee) {
self->link_to(testee);
// first test: 2 + 1 = 3
self->request(testee, plus_atom::value, 2, 1).then(
self->request(testee, infinite, plus_atom::value, 2, 1).then(
[=](result_atom, int r1) {
// second test: 2 - 1 = 1
self->request(testee, minus_atom::value, 2, 1).then(
self->request(testee, infinite, minus_atom::value, 2, 1).then(
[=](result_atom, int r2) {
// both tests succeeded
if (r1 == 3 && r2 == 1) {
......@@ -74,13 +75,14 @@ void tester(event_based_actor* self, const calculator_type& testee) {
);
}
} // namespace <anonymous>
int main() {
actor_system system;
void caf_main(actor_system& system) {
// test function-based impl
system.spawn(tester, system.spawn(typed_calculator_fun));
system.await_all_actors_done();
// test class-based impl
system.spawn(tester, system.spawn<typed_calculator_class>());
}
} // namespace <anonymous>
CAF_MAIN()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment