Trait Shield

Source
pub trait Shield
where Self: Future + Send + 'static, Self::Output: Send,
{ type ShieldFuture: Future<Output = Self::Output>; type TryShieldFuture: Future<Output = Result<Self::Output, Self::TryShieldError>>; type TryShieldError; // Required methods fn shield(self) -> Self::ShieldFuture; fn try_shield(self) -> Self::TryShieldFuture; }
Expand description

Adds methods to futures to prevent them from being aborted.

Required Associated Types§

Source

type ShieldFuture: Future<Output = Self::Output>

The Future returned from shield().

Source

type TryShieldFuture: Future<Output = Result<Self::Output, Self::TryShieldError>>

The Future returned from try_shield().

Source

type TryShieldError

The error returned from try_shield().

Required Methods§

Source

fn shield(self) -> Self::ShieldFuture

Prevent this future from being aborted by wrapping it in a task.

future.shield().await is equivalent to future.try_shield().await.unwrap().

§Panics

This function panics if awaiting the spawned task fails.

Source

fn try_shield(self) -> Self::TryShieldFuture

Prevent this future from being aborted by wrapping it in a task.

Since the task is created using tokio::spawn(), execution of this future starts immediately.

Implementors§