Implement Default for tokio_timer::Handle (#553)

This patch implements `Default` for `tokio_timer::Handle`. It returns a
`Handle` instance that is not bound to a specific timer. Instead, it
will use the timer for the current execution context. This is the same
strategy used by `tokio_reactor::Handle`.

Fixes #547
This commit is contained in:
Carl Lerche
2018-08-20 13:01:39 -07:00
committed by GitHub
parent 89639ec48b
commit c66b56c3fb
5 changed files with 97 additions and 14 deletions
+17
View File
@@ -7,6 +7,7 @@ mod support;
use support::*;
use tokio_timer::*;
use tokio_timer::timer::Handle;
use futures::Future;
@@ -486,3 +487,19 @@ fn reset_future_delay_after_fire() {
assert_ready!(delay);
});
}
#[test]
fn delay_with_default_handle() {
let handle = Handle::default();
let now = Instant::now();
let mut delay = handle.delay(now + ms(1));
mocked_with_now(now, |timer, _time| {
assert_not_ready!(delay);
turn(timer, ms(1));
assert_ready!(delay);
});
}