view rust/src/paramwaiter.rs @ 605:8dd63473b6d8 rust

config doesn't need Arc
author Matt Johnston <matt@ucc.asn.au>
date Fri, 17 Feb 2017 21:38:36 +0800
parents aff50ee77252
children 7bda01659426
line wrap: on
line source

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 ParamWaiter {
}

impl ParamWaiter {
    fn step(&mut self) -> Params {
        let mut p = Params::defaults();
        p.fridge_setpoint = 17.0 + 4.0*rand::random::<f32>();
        p
    }

    pub fn new() -> Self {
        ParamWaiter {}
    }

    pub fn stream(handle: &Handle) -> Box<Stream<Item=Params, Error=io::Error>> {
        let mut s = ParamWaiter::new();

        let dur = Duration::from_millis(4000);
        Interval::new(dur, handle).unwrap().map(move |()| {
            s.step()
        }).boxed()
    }
}