A trivial example program.
#include <string>
#include <iostream>
#include "caf/all.hpp"
using std::endl;
using std::string;
behavior mirror(event_based_actor* self) {
return {
[=](const string& what) -> string {
aout(
self) << what << endl;
return string(what.rbegin(), what.rend());
}
};
}
void hello_world(event_based_actor* self, const actor& buddy) {
self->request(buddy, std::chrono::seconds(10), "Hello World!").then(
[=](const string& what) {
aout(
self) << what << endl;
}
);
}
void caf_main(actor_system& system) {
auto mirror_actor = system.spawn(mirror);
system.spawn(hello_world, mirror_actor);
}
CAF_MAIN()
Root namespace of libcaf.
Definition: abstract_actor.hpp:44
actor_ostream aout(local_actor *self)
Convenience factory function for creating an actor output stream.