comparison rust/src/sensor.rs @ 588:038734052b20 rust

fiddling with futures-rs instead
author Matt Johnston <matt@ucc.asn.au>
date Fri, 16 Dec 2016 01:10:57 +0800
parents 646f03870762
children dccd8504aa38
comparison
equal deleted inserted replaced
587:646f03870762 588:038734052b20
1 use std::any::Any; 1 extern crate tokio_core;
2 extern crate futures;
2 3
3 use robots::actors::{Actor, ActorSystem, ActorCell, ActorContext, Props}; 4 use std::time::Duration;
5 use std;
6 use std::cell::RefCell;
7
8 use tokio_core::reactor::Interval;
9 use tokio_core::reactor::Core;
10 use tokio_core::reactor::Handle;
11 use futures::Stream;
12 use futures::Future;
13
14 pub struct Readings {
15
16 }
4 17
5 pub struct Sensor { 18 pub struct Sensor {
6 } 19 }
7 20
8 impl Actor for Sensor { 21 impl Sensor {
9 fn receive(&self, message: Box<Any>, context: ActorCell) { 22
10 if let Ok(message) = Box::<Any>::downcast::<String>(message) { 23 fn step(self) -> Readings {
11 println!("Sensor message! {}", message); 24 return Readings {}
12 } else { 25 }
13 println!("Sensor message!"); 26
14 } 27 pub fn new() -> Sensor {
28 Sensor {}
29 }
30
31 pub fn run(handle: &Handle) -> Box<Future<Item=Readings, Error = std::io::Error>> {
32 let s = Sensor::new();
33
34 Interval::new(Duration::from_millis(400), handle).map(|()| {
35 println!("each one");
36 // s.step()
37 Readings {}
38 }).boxed()
15 } 39 }
16 } 40 }
17 41
18 impl Sensor {
19
20 pub fn new(_dummy: ()) -> Sensor {
21 Sensor {}
22
23 }
24 }