Mercurial > templog
annotate rust/src/paramwaiter.rs @ 599:f71cf1ad745f rust
updated toml serde works OK
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 07 Feb 2017 22:35:29 +0800 |
parents | aff50ee77252 |
children | 7bda01659426 |
rev | line source |
---|---|
592 | 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 | |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
13 pub struct ParamWaiter { |
592 | 14 } |
15 | |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
16 impl ParamWaiter { |
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
17 fn step(&mut self) -> Params { |
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
18 let mut p = Params::defaults(); |
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
19 p.fridge_setpoint = 17.0 + 4.0*rand::random::<f32>(); |
592 | 20 p |
21 } | |
22 | |
23 pub fn new() -> Self { | |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
24 ParamWaiter {} |
592 | 25 } |
26 | |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
27 pub fn stream(handle: &Handle) -> Box<Stream<Item=Params, Error=io::Error>> { |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
28 let mut s = ParamWaiter::new(); |
592 | 29 |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
30 let dur = Duration::from_millis(4000); |
592 | 31 Interval::new(dur, handle).unwrap().map(move |()| { |
32 s.step() | |
33 }).boxed() | |
34 } | |
35 } | |
36 |