Skip to main content

CpuPoolExt

Trait CpuPoolExt 

Source
pub trait CpuPoolExt: CpuPool {
    // Provided method
    fn spawn<F, R>(
        &self,
        f: F,
    ) -> Pin<Box<dyn Future<Output = Result<R, CoreError>> + Send + 'static>>
       where F: FnOnce() -> R + Send + 'static,
             R: Send + 'static { ... }
}
Expand description

Ergonomic extension for CpuPool that adds a generic spawn with a return value. Auto-implemented for every T: CpuPool.

Provided Methods§

Source

fn spawn<F, R>( &self, f: F, ) -> Pin<Box<dyn Future<Output = Result<R, CoreError>> + Send + 'static>>
where F: FnOnce() -> R + Send + 'static, R: Send + 'static,

Spawn a CPU-intensive closure on the thread pool and await its result asynchronously.

The closure is executed on a rayon (or other CPU) worker thread while the caller’s async task yields. Useful for blocking work that would otherwise stall the Tokio executor.

Returns Err(CoreError::TaskAborted) if the worker panicked or the pool was shut down before the result could be delivered.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl<T: CpuPool + ?Sized> CpuPoolExt for T