Created
November 5, 2014 20:20
-
-
Save jsiwek/e738fce60ef57bc5a315 to your computer and use it in GitHub Desktop.
Example scoped_actor usage from actor-framework.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <caf/all.hpp> | |
#include <unistd.h> | |
using namespace std; | |
using namespace caf; | |
struct foo { | |
actor a; | |
~foo() | |
{ | |
cout << "~foo start" << endl; | |
scoped_actor self; | |
self->sync_send(a, atom("shutdown")).await( | |
on(atom("ok")) >> [=] {} | |
); | |
cout << "~foo end" << endl; | |
} | |
}; | |
behavior my_actor(event_based_actor* self) | |
{ | |
return { | |
on(atom("work")) >> [=] | |
{ | |
sleep(1); | |
}, | |
on(atom("shutdown")) >> [=] | |
{ | |
self->quit(); | |
return atom("ok"); | |
} | |
}; | |
} | |
int main() | |
{ | |
auto f = new foo{spawn(my_actor)}; | |
anon_send(f->a, atom("work")); | |
anon_send(f->a, atom("work")); | |
anon_send(f->a, atom("work")); | |
delete f; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment