comparison 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
comparison
equal deleted inserted replaced
592:03b48ec0bb03 593:bf138339d20a
7 use rustc_serialize::json; 7 use rustc_serialize::json;
8 8
9 mod sensor; 9 mod sensor;
10 mod fridge; 10 mod fridge;
11 mod types; 11 mod types;
12 mod configwaiter; 12 mod paramwaiter;
13 13
14 use types::*; 14 use types::*;
15 15
16 fn main() { 16 fn main() {
17 println!("Wort Templog"); 17 println!("Wort Templog");
18 18
19 let paramh = ParamHolder::new(); 19 let mut paramh = ParamHolder::new();
20 let mut readings = Readings::new(); 20 let mut readings = Readings::new();
21 let mut fridge = fridge::Fridge::new(&paramh.p); 21 let mut fridge = fridge::Fridge::new(paramh.p.clone());
22 22
23 let mut core = Core::new().unwrap(); 23 let mut core = Core::new().unwrap();
24 let handle = core.handle(); 24 let handle = core.handle();
25 25
26 let s = sensor::Sensor::run(&handle, 400, "sens1".to_string()); 26 let s = sensor::Sensor::run(&handle, 400, "sens1".to_string());
27 let t = sensor::Sensor::run(&handle, 747, "frid".to_string()); 27 let w = paramwaiter::ParamWaiter::run(&handle, 3000);
28 let w = configwaiter::ConfigWaiter::run(&handle, 3000);
29 28
30 let h = s.for_each(|r| { 29 let h = s.for_each(move |r| {
31 fridge.set_params(&paramh.p); 30 readings.push(r);
32 println!("readings {:?}", r); 31 println!("readings {:?}", readings);
33 Ok(()) 32 Ok(())
34 }); 33 });
35 34
36 let i = t.for_each(|r| { 35 let j = w.for_each(move |p| {
37 println!("fridgereadings {:?}", r); 36 fridge.set_params(&handle, p.clone());
37 paramh.p = p;
38 Ok(()) 38 Ok(())
39 }); 39 });
40 40
41 let j = w.for_each(move |ph| { 41 handle.spawn(h.map_err(|x| ()));
42 let paramh = ph; 42 handle.spawn(j.map_err(|x| ()));
43 fridge.set_params(&ph.p);
44 Ok(())
45 });
46 43
47 let all = h.select(j); 44 let forever = futures::empty::<(),()>();
48 45 core.run(forever);
49 core.run(all);
50 } 46 }
51 47