Introduction
This framework provides an implementation of the actor model for C++. It uses network transparent messaging to ease development of concurrent and distributed software.
To get started with the framework, please read the manual first.
Hello World Example
#include <string>
#include <iostream>
#include "caf/actor_ostream.hpp"
#include "caf/actor_system.hpp"
#include "caf/caf_main.hpp"
#include "caf/event_based_actor.hpp"
return {
[=](const std::string& what) -> std::string {
aout(self) << what << std::endl;
return std::string{what.rbegin(), what.rend()};
},
};
}
self->request(buddy, std::chrono::seconds(10), "Hello World!")
.then(
[=](const std::string& what) {
aout(self) << what << std::endl;
});
}
auto mirror_actor = sys.
spawn(mirror);
sys.
spawn(hello_world, mirror_actor);
}
CAF_MAIN()
Actor environment including scheduler, registry, and optional components such as a middleman.
Definition: actor_system.hpp:90
infer_handle_from_class_t< C > spawn(Ts &&... xs)
Returns a new actor of type C using xs... as constructor arguments.
Definition: actor_system.hpp:364
Identifies an untyped actor.
Definition: actor.hpp:29
Describes the behavior of an actor, i.e., provides a message handler and an optional timeout.
Definition: behavior.hpp:25
A cooperatively scheduled, event-based actor implementation.
Definition: event_based_actor.hpp:40
Root namespace of libcaf.
Definition: abstract_actor.hpp:29
CAF_CORE_EXPORT actor_ostream aout(local_actor *self)
Convenience factory function for creating an actor output stream.
More Examples
The Math Actor Example
shows the usage of receive_loop
and arg_match
. The Dining Philosophers Example
introduces event-based actors covers various features of CAF.