mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-29 00:00:11 +02:00
timer: introduce delay function shortcut (#1440)
This commit adds a simple delay shortcut to avoid writing Delay::new everywhere and removes usages of Delay::new.
This commit is contained in:
committed by
Carl Lerche
parent
357df38861
commit
2d56312b89
@@ -33,7 +33,7 @@ impl Delay {
|
||||
/// Only millisecond level resolution is guaranteed. There is no guarantee
|
||||
/// as to how the sub-millisecond portion of `deadline` will be handled.
|
||||
/// `Delay` should not be used for high-resolution timer use cases.
|
||||
pub fn new(deadline: Instant) -> Delay {
|
||||
pub(crate) fn new(deadline: Instant) -> Delay {
|
||||
let registration = Registration::new(deadline, Duration::from_millis(0));
|
||||
|
||||
Delay { registration }
|
||||
|
||||
@@ -59,9 +59,14 @@ pub use timer::{set_default, Timer};
|
||||
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
/// Create a Future that completes at `deadline`.
|
||||
pub fn delay(deadline: Instant) -> Delay {
|
||||
Delay::new(deadline)
|
||||
}
|
||||
|
||||
/// Create a Future that completes in `duration` from now.
|
||||
pub fn sleep(duration: Duration) -> Delay {
|
||||
Delay::new(Instant::now() + duration)
|
||||
delay(Instant::now() + duration)
|
||||
}
|
||||
|
||||
// ===== Internal utils =====
|
||||
|
||||
Reference in New Issue
Block a user