Mercurial > templog
diff rust/src/configwaiter.rs @ 592:03b48ec0bb03 rust
fridge, types, configwaiter
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 24 Dec 2016 00:14:58 +0800 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rust/src/configwaiter.rs Sat Dec 24 00:14:58 2016 +0800 @@ -0,0 +1,37 @@ +extern crate tokio_core; +extern crate futures; +extern crate rand; + +use std::time::Duration; +use std::io; + +use tokio_core::reactor::Interval; +use tokio_core::reactor::Handle; +use futures::Stream; +use types::*; + +pub struct ConfigWaiter { +} + +impl ConfigWaiter { + fn step(&mut self) -> ParamHolder { + let mut p = ParamHolder::new(); + let mut rng = rand::thread_rng(); + p.p.fridge_setpoint = rand::random::<f32>(); + p + } + + pub fn new() -> Self { + ConfigWaiter {} + } + + pub fn run(handle: &Handle, rate: u64) -> Box<Stream<Item=ParamHolder, Error=io::Error>> { + let mut s = ConfigWaiter::new(); + + let dur = Duration::from_millis(rate); + Interval::new(dur, handle).unwrap().map(move |()| { + s.step() + }).boxed() + } +} +