pub trait Timer: Send + Sync {
// Required methods
fn once<'async_trait>(
duration_millis: u32,
) -> Pin<Box<dyn Future<Output = Self> + Send + 'async_trait>>
where Self: 'async_trait;
fn interval<'async_trait>(
duration_millis: u32,
) -> Pin<Box<dyn Future<Output = Self> + Send + 'async_trait>>
where Self: 'async_trait;
fn cancel<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn once_sync(duration_millis: u32) -> Self;
fn interval_sync(duration_millis: u32) -> Self;
fn cancel_sync(&mut self);
fn tick<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = u32> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Trait for timer functionality across async runtimes.
Provides a unified interface for one-shot and interval timers that work with any supported async runtime.
§Examples
use product_os_async_executor::{Timer, TokioExecutor};
#[tokio::main]
async fn main() {
// Create an interval timer that fires every 100ms
let mut timer = TokioExecutor::interval(100).await;
// Wait for the first tick
let elapsed = timer.tick().await;
println!("Elapsed: {}ms", elapsed);
}Required Methods§
Sourcefn once<'async_trait>(
duration_millis: u32,
) -> Pin<Box<dyn Future<Output = Self> + Send + 'async_trait>>where
Self: 'async_trait,
fn once<'async_trait>(
duration_millis: u32,
) -> Pin<Box<dyn Future<Output = Self> + Send + 'async_trait>>where
Self: 'async_trait,
Creates a one-shot timer that fires after the specified duration.
Sourcefn interval<'async_trait>(
duration_millis: u32,
) -> Pin<Box<dyn Future<Output = Self> + Send + 'async_trait>>where
Self: 'async_trait,
fn interval<'async_trait>(
duration_millis: u32,
) -> Pin<Box<dyn Future<Output = Self> + Send + 'async_trait>>where
Self: 'async_trait,
Creates an interval timer that fires repeatedly at the specified interval.
Sourcefn cancel<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn cancel<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Cancels the timer.
Sourcefn interval_sync(duration_millis: u32) -> Self
fn interval_sync(duration_millis: u32) -> Self
Creates an interval timer synchronously.
Sourcefn cancel_sync(&mut self)
fn cancel_sync(&mut self)
Cancels the timer synchronously.
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.