mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-28 12:10:37 +00:00

This patch adds a new crate: tokio-timer. This crate provides an efficient timer implemeentation designed for use in Tokio based applications. The timer users a hierarchical hashed timer wheel algorithm with six levels, each having 64 slots. This allows the timer to have a resolution of 1ms while maintaining O(1) complexity for insert, removal, and firing of timeouts. There already exists a tokio-timer crate. This is a complete rewrite which solves the outstanding problems with the existing tokio-timer library. Closes #146.
47 lines
990 B
Rust
47 lines
990 B
Rust
extern crate futures;
|
|
extern crate tokio_executor;
|
|
extern crate tokio_timer;
|
|
|
|
#[macro_use]
|
|
mod support;
|
|
use support::*;
|
|
|
|
use tokio_timer::*;
|
|
|
|
use futures::{Stream};
|
|
|
|
#[test]
|
|
#[should_panic]
|
|
fn interval_zero_duration() {
|
|
mocked(|_, time| {
|
|
let _ = Interval::new(time.now(), ms(0));
|
|
});
|
|
}
|
|
|
|
#[test]
|
|
fn usage() {
|
|
mocked(|timer, time| {
|
|
let start = time.now();
|
|
let mut int = Interval::new(start, ms(300));
|
|
|
|
assert_ready!(int, Some(start));
|
|
assert_not_ready!(int);
|
|
|
|
advance(timer, ms(100));
|
|
assert_not_ready!(int);
|
|
|
|
advance(timer, ms(200));
|
|
assert_ready!(int, Some(start + ms(300)));
|
|
assert_not_ready!(int);
|
|
|
|
advance(timer, ms(400));
|
|
assert_ready!(int, Some(start + ms(600)));
|
|
assert_not_ready!(int);
|
|
|
|
advance(timer, ms(500));
|
|
assert_ready!(int, Some(start + ms(900)));
|
|
assert_ready!(int, Some(start + ms(1200)));
|
|
assert_not_ready!(int);
|
|
});
|
|
}
|