Skip to main content

Blocking

Trait Blocking 

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

    // Required method
    fn spawn_blocking<F, Output>(
        &self,
        operation: F,
        cancellation: &Cancellation,
    ) -> impl Future<Output = Result<Self::Handle<Output>, BlockingError>> + Send
       where F: FnOnce() -> Output + Send + 'static,
             Output: Send + 'static;
}
Expand description

Optional scheduler capability for owned synchronous work on blocking threads.

Required Associated Types§

Source

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

The owning completion handle returned by spawn_blocking, resolving to the closure’s output or a TaskError.

Required Methods§

Source

fn spawn_blocking<F, Output>( &self, operation: F, cancellation: &Cancellation, ) -> impl Future<Output = Result<Self::Handle<Output>, BlockingError>> + Send
where F: FnOnce() -> Output + Send + 'static, Output: Send + 'static,

Wait asynchronously for capacity and submit a closure, returning its owning completion handle.

Admission is lazy: an unpolled future submits nothing. Cancellation before admission returns BlockingError::Cancelled. A worker checks cancellation again before starting; cancellation after that boundary does not replace the closure’s result. The closure may capture a cancellation clone to cooperate while running.

Moving the handle transfers ownership. Dropping it requests that queued work be skipped, but cannot interrupt a running closure. Queued cancellation need not complete until a worker reaches the job. Await the handle before shutting down services the closure needs.

Implementations bound queued plus running jobs; waiting admission futures remain caller-owned. A running job retains its capacity until completion even if its handle is dropped. Job panics are reported as TaskError::Panicked.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§