extern crate actix;
extern crate futures;
use futures::Future;
use actix::prelude::*;
struct Ping(usize);
impl Message for Ping {
type Result = usize;
}
struct MyActor {
count: usize,
}
impl Actor for MyActor {
type Context = Context<Self>;
}
impl Handler<Ping> for MyActor {
type Result = usize;
fn handle(&mut self, msg: Ping, _: &mut Context<Self>) -> Self::Result {
self.count += msg.0;
self.count
}
}
fn main() {
let system = System::new("test");
let addr: Addr<Unsync, _> = MyActor{count: 10}.start();
let res = addr.send(Ping(10));
Arbiter::handle().spawn(
res.map(|res| {
println!("RESULT: {}", res == 20);
Arbiter::system().do_send(actix::msgs::SystemExit(0));
})
.map_err(|_| ()));
system.run();
}