mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-22 00:00:11 +02:00
Moves when to Timeout from TimeoutToken
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user