diff rust/src/main.rs @ 593:bf138339d20a rust

fiddling with timeouts and closures
author Matt Johnston <matt@ucc.asn.au>
date Tue, 27 Dec 2016 00:51:28 +0800
parents 03b48ec0bb03
children aff50ee77252
line wrap: on
line diff
--- a/rust/src/main.rs	Sat Dec 24 00:14:58 2016 +0800
+++ b/rust/src/main.rs	Tue Dec 27 00:51:28 2016 +0800
@@ -9,43 +9,39 @@
 mod sensor;
 mod fridge;
 mod types;
-mod configwaiter;
+mod paramwaiter;
 
 use types::*;
 
 fn main() {
     println!("Wort Templog");
 
-    let paramh = ParamHolder::new();
+    let mut paramh = ParamHolder::new();
     let mut readings = Readings::new();
-    let mut fridge = fridge::Fridge::new(&paramh.p);
+    let mut fridge = fridge::Fridge::new(paramh.p.clone());
 
     let mut core = Core::new().unwrap();
     let handle = core.handle();
 
     let s = sensor::Sensor::run(&handle, 400, "sens1".to_string());
-    let t = sensor::Sensor::run(&handle, 747, "frid".to_string());
-    let w = configwaiter::ConfigWaiter::run(&handle, 3000);
+    let w = paramwaiter::ParamWaiter::run(&handle, 3000);
 
-    let h = s.for_each(|r| {
-        fridge.set_params(&paramh.p);
-        println!("readings {:?}", r);
+    let h = s.for_each(move |r| {
+        readings.push(r);
+        println!("readings {:?}", readings);
         Ok(())
     });
 
-    let i = t.for_each(|r| {
-        println!("fridgereadings {:?}", r);
+    let j = w.for_each(move |p| {
+        fridge.set_params(&handle, p.clone());
+        paramh.p = p;
         Ok(())
     });
 
-    let j = w.for_each(move |ph| {
-        let paramh = ph;
-        fridge.set_params(&ph.p);
-        Ok(())
-    });
+    handle.spawn(h.map_err(|x| ()));
+    handle.spawn(j.map_err(|x| ()));
 
-    let all = h.select(j);
-
-    core.run(all);
+    let forever = futures::empty::<(),()>();
+    core.run(forever);
 }