extern crate actix;
extern crate futures;
extern crate tokio;
use actix::prelude::*;
use futures::Future;
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() {
System::run(|| {
let addr = MyActor { count: 10 }.start();
let res = addr.send(Ping(10));
tokio::spawn(
res.map(|res| {
println!("RESULT: {}", res == 20);
System::current().stop();
}).map_err(|_| ()),
);
});
}