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§
Sourcefn spawn(&self, fut: BoxFuture<()>) -> SpawnHandle
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.
Sourcefn now_monotonic(&self) -> Instant
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.
Sourcefn now_wall_clock(&self) -> SystemTime
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".