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 spawn_detached<Fut>(&self, fut: Fut)
where Fut: Future<Output = ()> + Send + 'static { ... }
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§
Sourcefn spawn<Fut>(
&self,
fut: Fut,
) -> DroppableFuture<impl Future<Output = Option<<Fut as Future>::Output>> + Send + 'static> ⓘ
fn spawn<Fut>( &self, fut: Fut, ) -> DroppableFuture<impl Future<Output = Option<<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
DroppableFutureis 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.
Sourcefn delay(&self, duration: Duration) -> impl Future<Output = ()> + Send
fn delay(&self, duration: Duration) -> impl Future<Output = ()> + Send
Wake in this amount of wall time
Provided Methods§
Sourcefn spawn_detached<Fut>(&self, fut: Fut)
fn spawn_detached<Fut>(&self, fut: Fut)
Spawn a future on the runtime without a join handle.
The output type is () because no completion signal or output is available to the
caller. If the spawned future panics, the panic does not propagate to the spawning
task; whether it is logged or swallowed is runtime-specific.
The default implementation spawns and immediately drops the join handle, relying on
the detach-on-drop contract of spawn.
Sourcefn timeout<'runtime, 'fut, Fut>(
&'runtime self,
duration: Duration,
fut: Fut,
) -> impl Future<Output = Option<<Fut as Future>::Output>> + Send + 'fut
fn timeout<'runtime, 'fut, Fut>( &'runtime self, duration: Duration, fut: Fut, ) -> impl Future<Output = Option<<Fut as Future>::Output>> + Send + 'fut
Race a future against the provided duration, returning None in case of timeout.
Sourcefn hook_signals(
&self,
signals: impl IntoIterator<Item = i32>,
) -> impl Stream<Item = i32> + Send + 'static
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".