pub trait Shield{
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§
Sourcetype TryShieldFuture: Future<Output = Result<Self::Output, Self::TryShieldError>>
type TryShieldFuture: Future<Output = Result<Self::Output, Self::TryShieldError>>
The Future
returned from try_shield()
.
Sourcetype TryShieldError
type TryShieldError
The error returned from try_shield()
.
Required Methods§
Sourcefn shield(self) -> Self::ShieldFuture
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.
Sourcefn try_shield(self) -> Self::TryShieldFuture
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.