Skip to main content

Sleep

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§

async fn sleep(&self, duration: Duration)

Resolves once duration has passed, by the caller’s clock.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

§

impl<TraitVariantBlanketType: SendSleep> Sleep for TraitVariantBlanketType