Mercurial > templog
comparison rust/src/paramwaiter.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 | rust/src/configwaiter.rs@03b48ec0bb03 |
children | aff50ee77252 |
comparison
equal
deleted
inserted
replaced
592:03b48ec0bb03 | 593:bf138339d20a |
---|---|
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 |