Skip to main content

Runtime

Trait Runtime 

Source
pub trait Runtime:
    Send
    + Sync
    + Debug
    + 'static {
    // Required methods
    fn spawn(&self, task: BoxFuture<()>);
    fn sleep(&self, duration: Duration) -> BoxFuture<()>;
    fn now(&self) -> Instant;

    // Provided method
    fn sleep_until(&self, deadline: Instant) -> BoxFuture<()> { ... }
}
Expand description

What a polyoxide crate needs of an async runtime: a detached spawn, a sleep, and a monotonic clock. Everything else in this crate (spawn’s Task, timeout, Interval) is built on these, so an implementor writes only these.

A client takes its runtime from its builder, and falls back to default_runtime(); nothing is process-wide.

Required Methods§

Source

fn spawn(&self, task: BoxFuture<()>)

Run task to completion, detached.

Source

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

Complete after duration. Any duration, Duration::MAX included, is valid.

Source

fn now(&self) -> Instant

The runtime’s monotonic clock.

Provided Methods§

Source

fn sleep_until(&self, deadline: Instant) -> BoxFuture<()>

Complete at deadline, at once when it has passed.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§