Skip to main content

RuntimeTrait

Trait RuntimeTrait 

Source
pub trait RuntimeTrait:
    Into<Runtime>
    + Clone
    + Send
    + Sync
    + 'static {
    // Required methods
    fn spawn<Fut>(
        &self,
        fut: Fut,
    ) -> DroppableFuture<impl Future<Output = Option<<Fut as Future>::Output>> + Send + 'static>
       where Fut: Future + Send + 'static,
             <Fut as Future>::Output: Send + 'static;
    fn delay(&self, duration: Duration) -> impl Future<Output = ()> + Send;
    fn interval(
        &self,
        period: Duration,
    ) -> impl Stream<Item = ()> + Send + 'static;
    fn block_on<Fut>(&self, fut: Fut) -> <Fut as Future>::Output
       where Fut: Future;

    // Provided methods
    fn timeout<'runtime, 'fut, Fut>(
        &'runtime self,
        duration: Duration,
        fut: Fut,
    ) -> impl Future<Output = Option<<Fut as Future>::Output>> + Send + 'fut
       where 'runtime: 'fut,
             Fut: Future + Send + 'fut,
             <Fut as Future>::Output: Send + 'static { ... }
    fn hook_signals(
        &self,
        signals: impl IntoIterator<Item = i32>,
    ) -> impl Stream<Item = i32> + Send + 'static { ... }
}
Expand description

A trait that covers async runtime behavior.

You likely do not need to name this type. For a type-erased runtime, see Runtime

Required Methods§

Source

fn spawn<Fut>( &self, fut: Fut, ) -> DroppableFuture<impl Future<Output = Option<<Fut as Future>::Output>> + Send + 'static>
where Fut: Future + Send + 'static, <Fut as Future>::Output: Send + 'static,

Spawn a future on the runtime, returning a future that has detach-on-drop semantics

As the various runtimes each has different behavior for spawn, implementations of this trait are expected to conform to the following:

  • detach on drop: If the returned DroppableFuture is dropped immediately, the task will continue to execute until completion.

  • unwinding: If the spawned future panics, this must not propagate to the join handle. Instead, the awaiting the join handle returns None in case of panic.

Source

fn delay(&self, duration: Duration) -> impl Future<Output = ()> + Send

Wake in this amount of wall time

Source

fn interval(&self, period: Duration) -> impl Stream<Item = ()> + Send + 'static

Returns a Stream that yields a () on the provided period

Source

fn block_on<Fut>(&self, fut: Fut) -> <Fut as Future>::Output
where Fut: Future,

Runtime implementation hook for blocking on a top level future.

Provided Methods§

Source

fn timeout<'runtime, 'fut, Fut>( &'runtime self, duration: Duration, fut: Fut, ) -> impl Future<Output = Option<<Fut as Future>::Output>> + Send + 'fut
where 'runtime: 'fut, Fut: Future + Send + 'fut, <Fut as Future>::Output: Send + 'static,

Race a future against the provided duration, returning None in case of timeout.

Source

fn hook_signals( &self, signals: impl IntoIterator<Item = i32>, ) -> impl Stream<Item = i32> + Send + 'static

trap and return a Stream of signals that match the provided signals

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl RuntimeTrait for SmolRuntime

Source§

fn spawn<Fut>( &self, fut: Fut, ) -> DroppableFuture<impl Future<Output = Option<<Fut as Future>::Output>> + Send + 'static>
where Fut: Future + Send + 'static, <Fut as Future>::Output: Send + 'static,

Source§

async fn delay(&self, duration: Duration)

Source§

fn interval(&self, period: Duration) -> impl Stream<Item = ()> + Send + 'static

Source§

fn block_on<Fut>(&self, fut: Fut) -> <Fut as Future>::Output
where Fut: Future,

Source§

fn hook_signals( &self, signals: impl IntoIterator<Item = i32>, ) -> impl Stream<Item = i32> + Send + 'static

Implementors§