aboutsummaryrefslogtreecommitdiffstats
path: root/src/timer.rs
diff options
context:
space:
mode:
authorJake McGinty <me@jake.su>2018-02-23 16:27:29 +0000
committerJake McGinty <me@jake.su>2018-02-23 16:27:29 +0000
commit075cfb30d4fa411f30ae7cfa37c9af2d2239fe38 (patch)
tree7d2c9629878f772db69df62ee6c5d9cf9b98934b /src/timer.rs
parentmake passive keepalive protocol-abiding (diff)
downloadwireguard-rs-075cfb30d4fa411f30ae7cfa37c9af2d2239fe38.tar.xz
wireguard-rs-075cfb30d4fa411f30ae7cfa37c9af2d2239fe38.zip
simplify timer calls
Diffstat (limited to 'src/timer.rs')
-rw-r--r--src/timer.rs17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/timer.rs b/src/timer.rs
index 6f8a64a..ee544fb 100644
--- a/src/timer.rs
+++ b/src/timer.rs
@@ -13,21 +13,20 @@ pub enum TimerMessage {
}
pub struct Timer {
+ handle: Handle,
timer: tokio_timer::Timer,
tx: unsync::mpsc::Sender<TimerMessage>,
rx: unsync::mpsc::Receiver<TimerMessage>,
}
-impl Default for Timer {
- fn default() -> Self {
+impl Timer {
+ pub fn new(handle: Handle) -> Self {
let (tx, rx) = unsync::mpsc::channel::<TimerMessage>(1024);
let timer = tokio_timer::Timer::default();
- Self { timer, tx, rx }
+ Self { handle, timer, tx, rx }
}
-}
-impl Timer {
- pub fn spawn_delayed(&mut self, handle: &Handle, delay: Duration, message: TimerMessage) {
+ pub fn spawn_delayed(&mut self, delay: Duration, message: TimerMessage) {
trace!("queuing timer message {:?}", &message);
let timer = self.timer.sleep(delay);
let future = timer.and_then({
@@ -36,11 +35,11 @@ impl Timer {
tx.clone().send(message).then(|_| Ok(()))
}
}).then(|_| Ok(()));
- handle.spawn(future);
+ self.handle.spawn(future);
}
- pub fn spawn_immediately(&mut self, handle: &Handle, message: TimerMessage) {
- handle.spawn(self.tx.clone().send(message).then(|_| Ok(())));
+ pub fn spawn_immediately(&mut self, message: TimerMessage) {
+ self.handle.spawn(self.tx.clone().send(message).then(|_| Ok(())));
}
}