comparison 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
comparison
equal deleted inserted replaced
591:4a944663fa8d 592:03b48ec0bb03
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 ConfigWaiter {
14 }
15
16 impl ConfigWaiter {
17 fn step(&mut self) -> ParamHolder {
18 let mut p = ParamHolder::new();
19 let mut rng = rand::thread_rng();
20 p.p.fridge_setpoint = rand::random::<f32>();
21 p
22 }
23
24 pub fn new() -> Self {
25 ConfigWaiter {}
26 }
27
28 pub fn run(handle: &Handle, rate: u64) -> Box<Stream<Item=ParamHolder, Error=io::Error>> {
29 let mut s = ConfigWaiter::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