From 5efac449b17006719067440017feaa4c030eec1e Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 26 Nov 2019 08:12:16 +0600 Subject: [PATCH] re-export time utils --- actix-rt/CHANGES.md | 2 ++ actix-rt/src/lib.rs | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/actix-rt/CHANGES.md b/actix-rt/CHANGES.md index 787a0b0b..27fefc3b 100644 --- a/actix-rt/CHANGES.md +++ b/actix-rt/CHANGES.md @@ -6,6 +6,8 @@ Added * Export `main` and `test` attribute macros +* Export `timer` module (re-export of tokio-timer) + ## [1.0.0-alpha.1] - 2019-11-22 diff --git a/actix-rt/src/lib.rs b/actix-rt/src/lib.rs index d9c6c58a..014b05fd 100644 --- a/actix-rt/src/lib.rs +++ b/actix-rt/src/lib.rs @@ -30,3 +30,23 @@ where Arbiter::spawn(f); } + +/// Utilities for tracking time. +pub mod time { + use std::time::{Duration, Instant}; + + pub use tokio_timer::Interval; + pub use tokio_timer::{delay, delay_for, Delay}; + + /// Creates new `Interval` that yields with interval of `duration`. The first + /// tick completes immediately. + pub fn interval(duration: Duration) -> Interval { + Interval::new(Instant::now(), duration) + } + + /// Creates new `Interval` that yields with interval of `period` with the + /// first tick completing at `at`. + pub fn interval_at(start: Instant, duration: Duration) -> Interval { + Interval::new(start, duration) + } +}