byor 1.0.0

Bring your own runtime!
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! Asynchronous timing.

use futures_lite::Stream;
use std::time::{Duration, Instant};

pub trait Time {
    /// Sleep for the specified duration, returning the instant when the sleep is complete.
    fn sleep(duration: Duration) -> impl Future<Output = Instant>;

    /// Sleep until the specified instant, returning the instant when the sleep is complete.
    fn sleep_until(deadline: Instant) -> impl Future<Output = Instant>;

    /// Create a stream of instants that yields with the given interval.
    fn interval(duration: Duration) -> impl Stream<Item = Instant>;

    /// Create a stream of instants that yields with the given interval, starting at the given instant.
    fn interval_at(start: Instant, duration: Duration) -> impl Stream<Item = Instant>;
}