mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-28 00:00:11 +02:00
Provide a timer implementation (#249)
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.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
use std::time::Instant;
|
||||
|
||||
/// Returns `Instant` values representing the current instant in time.
|
||||
///
|
||||
/// This allows customizing the source of time which is especially useful for
|
||||
/// testing.
|
||||
pub trait Now {
|
||||
/// Returns an instant corresponding to "now".
|
||||
fn now(&mut self) -> Instant;
|
||||
}
|
||||
|
||||
/// Returns the instant corresponding to now using a monotonic clock.
|
||||
#[derive(Debug)]
|
||||
pub struct SystemNow(());
|
||||
|
||||
impl SystemNow {
|
||||
/// Create a new `SystemNow`.
|
||||
pub fn new() -> SystemNow {
|
||||
SystemNow(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Now for SystemNow {
|
||||
fn now(&mut self) -> Instant {
|
||||
Instant::now()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user