pub trait AsyncTime {
type Interval: TimeInterval;
// Required methods
fn sleep(d: Duration) -> impl Future + Send;
fn tick(d: Duration) -> Self::Interval;
// Provided method
fn timeout<F>(
d: Duration,
func: F,
) -> impl Future<Output = Result<F::Output, ()>> + Send
where F: Future + Send { ... }
}Expand description
Trait for async time-related operations.
This trait defines the interface for time-related operations such as sleeping, creating intervals, and applying timeouts to futures.
§Associated Types
Interval- The type used for periodic timers
Required Associated Types§
Sourcetype Interval: TimeInterval
type Interval: TimeInterval
The type used for periodic timers.
Required Methods§
Sourcefn tick(d: Duration) -> Self::Interval
fn tick(d: Duration) -> Self::Interval
Create a periodic timer that ticks at the specified interval.
This method creates a timer that repeatedly fires at the specified interval, useful for implementing periodic tasks.
§Parameters
d- The interval between ticks
§Returns
An interval object that implements TimeInterval
Provided Methods§
Sourcefn timeout<F>(
d: Duration,
func: F,
) -> impl Future<Output = Result<F::Output, ()>> + Send
fn timeout<F>( d: Duration, func: F, ) -> impl Future<Output = Result<F::Output, ()>> + Send
Apply a timeout to a future.
This method returns a future that completes either when the provided future completes or when the specified timeout duration elapses, whichever happens first.
§Parameters
d- The timeout durationfunc- The future to apply the timeout to
§Returns
A future that resolves to Ok with the result of the original future
if it completes before the timeout, or Err(()) if the timeout elapses
first.
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.