diff 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
line wrap: on
line diff
--- a/rust/src/sensor.rs	Wed Dec 14 00:15:14 2016 +0800
+++ b/rust/src/sensor.rs	Fri Dec 16 01:10:57 2016 +0800
@@ -1,24 +1,41 @@
-use std::any::Any;
+extern crate tokio_core;
+extern crate futures;
+
+use std::time::Duration;
+use std;
+use std::cell::RefCell;
 
-use robots::actors::{Actor, ActorSystem, ActorCell, ActorContext, Props};
+use tokio_core::reactor::Interval;
+use tokio_core::reactor::Core;
+use tokio_core::reactor::Handle;
+use futures::Stream;
+use futures::Future;
+
+pub struct Readings {
+
+}
 
 pub struct Sensor {
 }
 
-impl Actor for Sensor {
-    fn receive(&self, message: Box<Any>, context: ActorCell) {
-        if let Ok(message) = Box::<Any>::downcast::<String>(message) {
-            println!("Sensor message! {}", message);
-        } else {
-            println!("Sensor message!");
-        }
+impl Sensor {
+
+    fn step(self) -> Readings {
+        return Readings {}
+    }
+
+    pub fn new() -> Sensor {
+        Sensor {}
+    }
+
+    pub fn run(handle: &Handle) -> Box<Future<Item=Readings, Error = std::io::Error>> {
+        let s = Sensor::new();
+
+        Interval::new(Duration::from_millis(400), handle).map(|()| {
+            println!("each one");
+     //       s.step()
+            Readings {}
+        }).boxed()
     }
 }
 
-impl Sensor {
-
-    pub fn new(_dummy: ()) -> Sensor {
-        Sensor {}
-
-    }
-}