pub trait TimeAbstraction {
// Required methods
fn now() -> Instant;
async fn sleep_until(deadline: Instant) -> Result<(), Error>;
fn interval(period: Duration) -> impl Interval;
// Provided methods
async fn sleep(duration: Duration) -> Result<(), Error> { ... }
async fn timeout_at<F>(
deadline: Instant,
future: F,
) -> Result<<F as IntoFuture>::Output, Either<Exceeded, Error>>
where Self: Sized,
F: IntoFuture { ... }
}
Expand description
TimeAbstraction
is used to perform time-related operations in a platform-agnostic manner.
Required Methods§
Sourceasync fn sleep_until(deadline: Instant) -> Result<(), Error>
async fn sleep_until(deadline: Instant) -> Result<(), Error>
Returns a future that resolves successfully at the specified deadline
(or earlier with an error).
Sourcefn interval(period: Duration) -> impl Interval
fn interval(period: Duration) -> impl Interval
Returns an Interval
that will yield an item straight away and then once every period
(unless there is an error).
If the stream consumer falls behind and multiple periods go by between reading from the stream, the stream will keep track of the missed periods and instantly yield them until caught up.
Provided Methods§
Sourceasync fn sleep(duration: Duration) -> Result<(), Error>
async fn sleep(duration: Duration) -> Result<(), Error>
Returns a future that resolves successfully after the specified duration
(or earlier with an error).
If the duration
overflows Instant
, the method sleeps for an unspecified time.
Sourceasync fn timeout_at<F>(
deadline: Instant,
future: F,
) -> Result<<F as IntoFuture>::Output, Either<Exceeded, Error>>where
Self: Sized,
F: IntoFuture,
async fn timeout_at<F>(
deadline: Instant,
future: F,
) -> Result<<F as IntoFuture>::Output, Either<Exceeded, Error>>where
Self: Sized,
F: IntoFuture,
Returns a future that will resolve when: the wrapped future resolves, the deadline
is reached, or there is an
error.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.