async_timer/
lib.rs

1//! Async timer lib
2//!
3//! ## Timers
4//!
5//! - [Oneshot](oneshot/trait.Oneshot.html) interface to one-shot [Timer](oneshot/type.Timer.html)
6//!
7//! ## Primitives
8//!
9//! - [Timed](enum.Timed.html) - A wrapper over future that allows to limit time for the future to resolve.
10//! - [Interval](struct.Interval.html) - Periodic timer, that on each completition returns itself to poll once again with the same interval.
11//!
12//! ## Features
13//!
14//! - `tokio_on` - Enables implementations that require platform's event loop
15#![warn(missing_docs)]
16
17#![no_std]
18#![cfg_attr(feature = "cargo-clippy", allow(clippy::style))]
19
20#[allow(unused_imports)]
21extern crate alloc;
22#[cfg(not(feature = "no_std"))]
23extern crate std;
24
25use core::{time, future};
26
27#[macro_use]
28mod utils;
29pub mod oneshot;
30mod timed;
31mod interval;
32
33pub use oneshot::Oneshot;
34pub use timed::{Timed, Expired};
35pub use interval::Interval;
36
37///Run future in timed fashion using default Platform timer.
38pub fn timed<F: future::Future>(job: F, timeout: time::Duration) -> impl future::Future<Output=Result<F::Output, Expired<F, oneshot::Timer>>> {
39    unsafe {
40        Timed::platform_new_unchecked(job, timeout)
41    }
42}
43
44///Creates interval with default Platform timer.
45pub fn interval(interval: time::Duration) -> Interval<oneshot::Timer> {
46    Interval::platform_new(interval)
47}