Skip to main content

Runtime

Trait Runtime 

Source
pub trait Runtime:
    Send
    + Sync
    + 'static {
    // Required methods
    fn spawn(&self, fut: BoxFuture<()>) -> SpawnHandle;
    fn sleep(&self, duration: Duration) -> BoxFuture<()>;
    fn now_monotonic(&self) -> Instant;
    fn now_wall_clock(&self) -> SystemTime;
}
Expand description

Async runtime abstraction.

Every method takes &self so a single runtime handle (typically wrapped in Arc<dyn Runtime>) can be shared across spawned tasks.

Required Methods§

Source

fn spawn(&self, fut: BoxFuture<()>) -> SpawnHandle

Spawn a future to run on the runtime. The returned SpawnHandle can be abort()-ed to request cancellation; dropping the handle detaches the task without cancelling it.

Source

fn sleep(&self, duration: Duration) -> BoxFuture<()>

Yield control for at least duration.

Source

fn now_monotonic(&self) -> Instant

Monotonic instant — strictly non-decreasing across calls on the same runtime. Used for RTT measurement, retry timers, and any duration arithmetic that must not be affected by wall-clock skew.

Source

fn now_wall_clock(&self) -> SystemTime

Wall-clock time. May jump forward or backward as the system clock is adjusted. Used for timestamp-bound material (cookie buckets, PoW challenge expiry).

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§