Mercurial > templog
comparison rust/src/fridge.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 | 03b48ec0bb03 |
children | aff50ee77252 |
comparison
equal
deleted
inserted
replaced
592:03b48ec0bb03 | 593:bf138339d20a |
---|---|
1 use std::io; | |
2 use std::time::Duration; | |
3 | |
4 use futures::Future; | |
5 use tokio_core::reactor::Timeout; | |
6 use tokio_core::reactor::Handle; | |
7 | |
1 use types::*; | 8 use types::*; |
2 | 9 |
3 pub struct Fridge<'a> { | 10 pub struct Fridge { |
4 params: &'a Params, | 11 params: Params, |
12 temp_wort: Option<f32>, | |
13 temp_fridge: Option<f32>, | |
14 | |
15 // timeouts to wake ourself up again | |
16 //overshoot_timeout: Option<Future<Item=(), Error=io::Error>>, | |
17 //fridgeoff_timeout: Option<Future<Item=(), Error=io::Error>>, | |
18 wortvalid_timeout: Option<Timeout>, | |
5 } | 19 } |
6 | 20 |
7 impl<'a> Fridge<'a> { | 21 impl Fridge { |
8 pub fn new(p: &'a Params) -> Fridge<'a> { | 22 pub fn new(p: Params) -> Fridge { |
9 Fridge { params: p } | 23 Fridge { |
24 params: p, | |
25 temp_wort: None, | |
26 temp_fridge: None, | |
27 //overshoot_timeout: None, | |
28 //fridgeoff_timeout: None, | |
29 wortvalid_timeout: None, | |
30 } | |
10 } | 31 } |
11 | 32 |
12 pub fn set_params(&mut self, p: &'a Params) { | 33 fn tick(&mut self, handle: &Handle) { |
34 | |
35 } | |
36 | |
37 pub fn set_params(&mut self, handle: &Handle, p: Params) { | |
13 self.params = p; | 38 self.params = p; |
39 println!("params {:?}", self.params); | |
40 | |
41 self.tick(handle); | |
42 } | |
43 | |
44 pub fn set_temps(&mut self, handle: &Handle, | |
45 wort: Option<f32>, fridge: Option<f32>) { | |
46 self.temp_wort = wort; | |
47 self.temp_fridge = fridge; | |
48 | |
49 if let Some(_) = self.temp_wort { | |
50 // set a new timeout, replacing any existing | |
51 let dur = Duration::new(10, 0); // XXX | |
52 let t = Timeout::new(dur, handle).unwrap(); | |
53 /* | |
54 handle.spawn(t.and_then(|_| { | |
55 self.tick(handle); | |
56 Ok(()) | |
57 }).map_err(|x| ())); | |
58 */ | |
59 self.wortvalid_timeout = Some(t); | |
60 } | |
61 | |
62 self.tick(handle); | |
14 } | 63 } |
15 | 64 |
16 } | 65 } |