Moves when to Timeout from TimeoutToken

This commit is contained in:
Paul Colomiets
2016-10-06 21:11:46 +03:00
parent a99b2529e0
commit 411caa786d
3 changed files with 9 additions and 18 deletions
+5 -3
View File
@@ -13,13 +13,14 @@ use reactor::timeout_token::TimeoutToken;
/// A future representing the notification that a timeout has occurred.
///
/// Timeouts are created through the `LoopHandle::timeout` or
/// `LoopHandle::timeout_at` methods indicating when a timeout should fire at.
/// Timeouts are created through the `Timeout::new` or
/// `Timeout::new_at` methods indicating when a timeout should fire at.
/// Note that timeouts are not intended for high resolution timers, but rather
/// they will likely fire some granularity after the exact instant that they're
/// otherwise indicated to fire at.
pub struct Timeout {
token: TimeoutToken,
when: Instant,
handle: Remote,
}
@@ -41,6 +42,7 @@ impl Timeout {
pub fn new_at(at: Instant, handle: &Handle) -> io::Result<Timeout> {
Ok(Timeout {
token: try!(TimeoutToken::new(at, &handle)),
when: at,
handle: handle.remote().clone(),
})
}
@@ -53,7 +55,7 @@ impl Future for Timeout {
fn poll(&mut self) -> Poll<(), io::Error> {
// TODO: is this fast enough?
let now = Instant::now();
if *self.token.when() <= now {
if self.when <= now {
Ok(Async::Ready(()))
} else {
self.token.update_timeout(&self.handle);