pub trait AsyncSpawner: Send + Sync {
// Required methods
fn spawn_supervised(
&self,
label: &'static str,
task: BoxFuture<'static, ()>,
) -> Result<(), SpawnError>;
fn spawn_blocking_erased(
&self,
label: &'static str,
work: BoxedBlockingWork,
) -> Result<Receiver<ErasedBlockingResult>, SpawnError>;
fn request_cancel(&self);
fn is_cancelled(&self) -> bool;
fn shutdown(&self) -> BoxFuture<'static, ()>;
}Expand description
Object-safe host-provided async spawner.
spawn_blocking is exposed as an erased operation on the trait so the
runtime can hold Arc<dyn AsyncSpawner>. Typed callers use the helper
spawn_blocking wrapper below, which downcasts the boxed result back to
the requested type.
Required Methods§
Sourcefn spawn_supervised(
&self,
label: &'static str,
task: BoxFuture<'static, ()>,
) -> Result<(), SpawnError>
fn spawn_supervised( &self, label: &'static str, task: BoxFuture<'static, ()>, ) -> Result<(), SpawnError>
Spawn a supervised async task.
Sourcefn spawn_blocking_erased(
&self,
label: &'static str,
work: BoxedBlockingWork,
) -> Result<Receiver<ErasedBlockingResult>, SpawnError>
fn spawn_blocking_erased( &self, label: &'static str, work: BoxedBlockingWork, ) -> Result<Receiver<ErasedBlockingResult>, SpawnError>
Spawn a blocking task and return an erased result receiver.
Sourcefn request_cancel(&self)
fn request_cancel(&self)
Broadcast cancellation to all supervised tasks.
Sourcefn is_cancelled(&self) -> bool
fn is_cancelled(&self) -> bool
Has cancellation already been requested?
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".