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
+2 -13
View File
@@ -8,7 +8,6 @@ use reactor::{Message, Handle, Remote};
/// A token that identifies an active timeout.
pub struct TimeoutToken {
token: usize,
when: Instant,
}
impl TimeoutToken {
@@ -17,23 +16,13 @@ impl TimeoutToken {
pub fn new(at: Instant, handle: &Handle) -> io::Result<TimeoutToken> {
match handle.inner.upgrade() {
Some(inner) => {
let (token, when) = try!(inner.borrow_mut().add_timeout(at));
Ok(TimeoutToken { token: token, when: when })
let token = inner.borrow_mut().add_timeout(at);
Ok(TimeoutToken { token: token })
}
None => Err(io::Error::new(io::ErrorKind::Other, "event loop gone")),
}
}
/// Returns the instant in time when this timeout token will "fire".
///
/// Note that this instant may *not* be the instant that was passed in when
/// the timeout was created. The event loop does not support high resolution
/// timers, so the exact resolution of when a timeout may fire may be
/// slightly fudged.
pub fn when(&self) -> &Instant {
&self.when
}
/// Updates a previously added timeout to notify a new task instead.
///
/// # Panics