comparison rust/src/fridge.rs @ 611:f3e39e2107fd rust

still doesn't compile, improvements to TemplogError and tokio curl though
author Matt Johnston <matt@ucc.asn.au>
date Tue, 28 Feb 2017 22:58:47 +0800
parents 7bda01659426
children f153aec221be
comparison
equal deleted inserted replaced
610:af0dac00d40b 611:f3e39e2107fd
2 extern crate tokio_core; 2 extern crate tokio_core;
3 3
4 use std; 4 use std;
5 use std::io; 5 use std::io;
6 use std::mem; 6 use std::mem;
7 use std::error::Error;
7 use std::time::{Duration,Instant}; 8 use std::time::{Duration,Instant};
8 9
9 use futures::{Future,future,Sink,Stream}; 10 use futures::{Future,future,Sink,Stream};
10 use tokio_core::reactor::{Timeout,Handle}; 11 use tokio_core::reactor::{Timeout,Handle};
11 use futures::sync::{mpsc}; 12 use futures::sync::{mpsc};
36 } 37 }
37 38
38 impl Sink for Fridge { 39 impl Sink for Fridge {
39 40
40 type SinkItem = Message; 41 type SinkItem = Message;
41 type SinkError = std::io::Error; 42 type SinkError = TemplogError;
42 43
43 fn start_send(&mut self, msg: Message) 44 fn start_send(&mut self, msg: Message)
44 -> futures::StartSend<Self::SinkItem, Self::SinkError> { 45 -> futures::StartSend<Self::SinkItem, Self::SinkError> {
45 self.process_msg(msg); 46 self.process_msg(msg);
46 Ok(futures::AsyncSink::Ready) 47 Ok(futures::AsyncSink::Ready)
87 /// * overshoot calculation 88 /// * overshoot calculation
88 /// * minimum fridge-off time 89 /// * minimum fridge-off time
89 /// * invalid wort timeout 90 /// * invalid wort timeout
90 /// All specified in next_wakeup() 91 /// All specified in next_wakeup()
91 pub fn wakeups(&mut self) 92 pub fn wakeups(&mut self)
92 -> Box<Stream<Item=Message, Error=io::Error>> { 93 -> Box<Stream<Item=Message, Error=TemplogError>> {
93 mem::replace(&mut self.timeout_r, None) 94 mem::replace(&mut self.timeout_r, None)
94 .expect("Fridge::wakeups() can only be called once") 95 .expect("Fridge::wakeups() can only be called once")
95 .map(|v| Message::Tick(v)) 96 .map(|v| Message::Tick(v))
96 .map_err(|_| io::Error::new(io::ErrorKind::Other, "Something wrong with watcher timeout channel")) 97 .map_err(|e| TemplogError::new("wakeups() receive failed"))
97 .boxed() 98 .boxed()
98 } 99 }
99 100
100 /// Must be called after every state change. Turns the fridge on/off as required and 101 /// Must be called after every state change. Turns the fridge on/off as required and
101 /// schedules any future wakeups based on the present (new) state 102 /// schedules any future wakeups based on the present (new) state