async_timer/
lib.rs

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
//! Async timer lib
//!
//! ## Timers
//!
//! - [Oneshot](oneshot/trait.Oneshot.html) interface to one-shot [Timer](oneshot/type.Timer.html)
//!
//! ## Primitives
//!
//! - [Timed](enum.Timed.html) - A wrapper over future that allows to limit time for the future to resolve.
//! - [Interval](struct.Interval.html) - Periodic timer, that on each completition returns itself to poll once again with the same interval.
//!
//! ## Features
//!
//! - `tokio_on` - Enables implementations that require platform's event loop
#![warn(missing_docs)]

#![no_std]
#![cfg_attr(feature = "cargo-clippy", allow(clippy::style))]

#[allow(unused_imports)]
extern crate alloc;
#[cfg(not(feature = "no_std"))]
extern crate std;

use core::{time, future};

#[macro_use]
mod utils;
pub mod oneshot;
mod timed;
mod interval;

pub use oneshot::Oneshot;
pub use timed::{Timed, Expired};
pub use interval::Interval;

///Run future in timed fashion using default Platform timer.
pub fn timed<F: future::Future>(job: F, timeout: time::Duration) -> impl future::Future<Output=Result<F::Output, Expired<F, oneshot::Timer>>> {
    unsafe {
        Timed::platform_new_unchecked(job, timeout)
    }
}

///Creates interval with default Platform timer.
pub fn interval(interval: time::Duration) -> Interval<oneshot::Timer> {
    Interval::platform_new(interval)
}