602
|
1 extern crate tokio_core; |
|
2 extern crate futures; |
|
3 extern crate rand; |
|
4 |
|
5 use std::time::Duration; |
|
6 use std::io; |
|
7 |
|
8 use tokio_core::reactor::Interval; |
|
9 use tokio_core::reactor::Handle; |
|
10 use futures::Stream; |
|
11 use types::*; |
|
12 |
|
13 pub struct ParamWaiter { |
|
14 } |
|
15 |
|
16 impl ParamWaiter { |
|
17 fn step(&mut self) -> Params { |
|
18 let mut p = Params::defaults(); |
|
19 let mut rng = rand::thread_rng(); |
|
20 p.fridge_setpoint = 17.0 + 4.0*rand::random::<f32>(); |
|
21 p |
|
22 } |
|
23 |
|
24 pub fn new() -> Self { |
|
25 ParamWaiter {} |
|
26 } |
|
27 |
|
28 pub fn run(handle: &Handle, rate: u64) -> Box<Stream<Item=Params, Error=io::Error>> { |
|
29 let mut s = ParamWaiter::new(); |
|
30 |
|
31 let dur = Duration::from_millis(rate); |
|
32 Interval::new(dur, handle).unwrap().map(move |()| { |
|
33 s.step() |
|
34 }).boxed() |
|
35 } |
|
36 } |
|
37 |