1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#![doc(html_root_url = "https://docs.rs/tokio-timer/0.2.7")]
#![deny(missing_docs, warnings, missing_debug_implementations)]
extern crate tokio_executor;
extern crate crossbeam_utils;
#[macro_use]
extern crate futures;
extern crate slab;
pub mod clock;
pub mod delay_queue;
pub mod timeout;
pub mod timer;
mod atomic;
mod deadline;
mod delay;
mod error;
mod interval;
mod wheel;
#[deprecated(since = "0.2.6", note = "use Timeout instead")]
#[doc(hidden)]
#[allow(deprecated)]
pub use self::deadline::{Deadline, DeadlineError};
#[doc(inline)]
pub use self::delay_queue::DelayQueue;
pub use self::delay::Delay;
pub use self::error::Error;
pub use self::interval::Interval;
#[doc(inline)]
pub use self::timeout::Timeout;
pub use self::timer::{with_default, Timer};
use std::time::{Duration, Instant};
pub fn sleep(duration: Duration) -> Delay {
Delay::new(Instant::now() + duration)
}
enum Round {
Up,
Down,
}
#[inline]
fn ms(duration: Duration, round: Round) -> u64 {
const NANOS_PER_MILLI: u32 = 1_000_000;
const MILLIS_PER_SEC: u64 = 1_000;
let millis = match round {
Round::Up => (duration.subsec_nanos() + NANOS_PER_MILLI - 1) / NANOS_PER_MILLI,
Round::Down => duration.subsec_nanos() / NANOS_PER_MILLI,
};
duration.as_secs().saturating_mul(MILLIS_PER_SEC).saturating_add(millis as u64)
}