Skip to main content

Spawn

Trait Spawn 

Source
pub trait Spawn {
    type Handle<Output>: Future<Output = Result<Output, TaskError>> + Send + 'static
       where Output: Send + 'static;

    // Required method
    fn spawn<FutureType>(
        &self,
        future: FutureType,
    ) -> Result<Self::Handle<FutureType::Output>, SpawnError>
       where FutureType: Future + Send + 'static,
             FutureType::Output: Send + 'static;
}
Expand description

The common spawning contract for schedulers and their handles.

Required Associated Types§

Source

type Handle<Output>: Future<Output = Result<Output, TaskError>> + Send + 'static where Output: Send + 'static

The runtime’s awaitable task handle. Runtime adapters may use their own representation while preserving the ownership and result contract.

Required Methods§

Source

fn spawn<FutureType>( &self, future: FutureType, ) -> Result<Self::Handle<FutureType::Output>, SpawnError>
where FutureType: Future + Send + 'static, FutureType::Output: Send + 'static,

Register a task with this scheduler before making it runnable.

The returned handle owns the execution lifetime. Dropping it requests destruction after any active poll returns; moving it transfers ownership. Await it explicitly for completion, or cancel cooperatively and then await. If the scheduler is closed, the future is dropped without being polled.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§