Mercurial > templog
diff rust/src/main.rs @ 609:7bda01659426 rust
not building, paramwaiter work
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 18 Feb 2017 00:21:10 +0800 |
parents | 282fae1c12e4 |
children | f3e39e2107fd |
line wrap: on
line diff
--- a/rust/src/main.rs Fri Feb 17 23:07:33 2017 +0800 +++ b/rust/src/main.rs Sat Feb 18 00:21:10 2017 +0800 @@ -5,6 +5,8 @@ extern crate env_logger; extern crate rustc_serialize; extern crate time; +extern crate tokio_curl; +extern crate curl; #[macro_use] extern crate lazy_static; @@ -18,9 +20,6 @@ extern crate docopt; use std::io; -use std::time::{Duration,Instant}; -use std::ops::Not; -use std::cell::Cell; use tokio_core::reactor::Core; use futures::{Stream,Sink,Future}; @@ -29,7 +28,7 @@ mod config; mod sensor; -pub mod fridge; +mod fridge; mod types; mod paramwaiter; @@ -175,28 +174,3 @@ run(&config, args.flag_nowait, args.flag_test); } - -/// Call closures with a rate limit. Useful for log message ratelimiting -pub struct NotTooOften { - last: Cell<Instant>, - limit: Duration, -} - -impl NotTooOften { - pub fn new(limit_secs: u64) -> Self { - NotTooOften { - limit: Duration::new(limit_secs, 0), - last: Cell::new(Instant::now() - Duration::new(limit_secs+1, 0)), - } - } - - pub fn and_then<F>(&self, op: F) - where F: Fn() { - let now = Instant::now(); - if now - self.last.get() > self.limit { - self.last.set(now); - op(); - } - } -} -