comparison rust/src/paramwaiter.rs @ 594:aff50ee77252 rust

rust working better now with streams and sinks.
author Matt Johnston <matt@ucc.asn.au>
date Wed, 04 Jan 2017 17:18:44 +0800
parents bf138339d20a
children 7bda01659426
comparison
equal deleted inserted replaced
593:bf138339d20a 594:aff50ee77252
14 } 14 }
15 15
16 impl ParamWaiter { 16 impl ParamWaiter {
17 fn step(&mut self) -> Params { 17 fn step(&mut self) -> Params {
18 let mut p = Params::defaults(); 18 let mut p = Params::defaults();
19 let mut rng = rand::thread_rng();
20 p.fridge_setpoint = 17.0 + 4.0*rand::random::<f32>(); 19 p.fridge_setpoint = 17.0 + 4.0*rand::random::<f32>();
21 p 20 p
22 } 21 }
23 22
24 pub fn new() -> Self { 23 pub fn new() -> Self {
25 ParamWaiter {} 24 ParamWaiter {}
26 } 25 }
27 26
28 pub fn run(handle: &Handle, rate: u64) -> Box<Stream<Item=Params, Error=io::Error>> { 27 pub fn stream(handle: &Handle) -> Box<Stream<Item=Params, Error=io::Error>> {
29 let mut s = ParamWaiter::new(); 28 let mut s = ParamWaiter::new();
30 29
31 let dur = Duration::from_millis(rate); 30 let dur = Duration::from_millis(4000);
32 Interval::new(dur, handle).unwrap().map(move |()| { 31 Interval::new(dur, handle).unwrap().map(move |()| {
33 s.step() 32 s.step()
34 }).boxed() 33 }).boxed()
35 } 34 }
36 } 35 }