diff options
author | Jake McGinty <me@jake.su> | 2018-02-23 16:27:29 +0000 |
---|---|---|
committer | Jake McGinty <me@jake.su> | 2018-02-23 16:27:29 +0000 |
commit | 075cfb30d4fa411f30ae7cfa37c9af2d2239fe38 (patch) | |
tree | 7d2c9629878f772db69df62ee6c5d9cf9b98934b /src/timer.rs | |
parent | make passive keepalive protocol-abiding (diff) | |
download | wireguard-rs-075cfb30d4fa411f30ae7cfa37c9af2d2239fe38.tar.xz wireguard-rs-075cfb30d4fa411f30ae7cfa37c9af2d2239fe38.zip |
simplify timer calls
Diffstat (limited to 'src/timer.rs')
-rw-r--r-- | src/timer.rs | 17 |
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(()))); } } |