pub trait Timers: Clock {
type Timer: Send;
// Required methods
fn timer(&self) -> Self::Timer;
fn timer_wait_until(
&self,
timer: &mut Self::Timer,
deadline: Instant,
cancellation: &Cancellation,
) -> impl Future<Output = OperationResult<()>> + Send;
}Expand description
Experimental reusable timer capability for the timer benchmark. This is not a settled public contract.
Construct resources through timer to establish their scheduler compatibility before waiting. Waiting always receives its scheduler and cancellation explicitly; incompatible scheduler/resource pairings are rejected with io::ErrorKind::InvalidInput. Only one waiter can borrow the resource. Dropping a wait retains its registration, which may cause a later wake of the previous task. Dropping the resource retires it; forgetting it may leak registration capacity but cannot retain borrowed application memory. Cancellation observed after admission disarms its registration; pre-cancellation leaves existing state unchanged. Deadline replacement happens on first poll, including an earlier replacement.
use base_scheduler::{Cancellation, OperationResult, Timers};
use std::time::Duration;
async fn delay<S: Timers>(scheduler: &S, cancellation: &Cancellation) -> OperationResult<()> {
let mut timer = scheduler.timer();
let deadline = scheduler.now() + Duration::from_secs(1);
scheduler.timer_wait_until(&mut timer, deadline, cancellation).await
}Required Associated Types§
Sourcetype Timer: Send
type Timer: Send
Reusable timer state created by timer and borrowed by each timer_wait_until.
Required Methods§
Sourcefn timer(&self) -> Self::Timer
fn timer(&self) -> Self::Timer
Construct reusable state compatible with this scheduler, without registering a deadline or selecting a worker. Construction is infallible even after closure; waits retain the backend’s clock admission rules.
Sourcefn timer_wait_until(
&self,
timer: &mut Self::Timer,
deadline: Instant,
cancellation: &Cancellation,
) -> impl Future<Output = OperationResult<()>> + Send
fn timer_wait_until( &self, timer: &mut Self::Timer, deadline: Instant, cancellation: &Cancellation, ) -> impl Future<Output = OperationResult<()>> + Send
Wait until an absolute deadline using retained timer state. Constructing an unpolled future leaves the resource unchanged.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".