Trait Sleep
pub trait Sleep {
// Required method
async fn sleep(&self, duration: Duration);
}Expand description
Waits out a duration. The runner’s only contact with time.
Defined without a Send bound, as the ports are, and trait_variant
derives SendSleep, whose future is Send. Bind Sleep in generic code:
it is the weaker requirement and accepts both.
§Examples
A sleep that records what it was asked for and returns at once, as a test’s does:
use core::cell::RefCell;
use core::time::Duration;
use happenstance_sync::runner::Sleep;
#[derive(Default)]
struct Recorded(RefCell<Vec<Duration>>);
impl Sleep for Recorded {
async fn sleep(&self, duration: Duration) {
self.0.borrow_mut().push(duration);
}
}Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".