Skip to main content

ExecutorBlocking

Trait ExecutorBlocking 

Source
pub trait ExecutorBlocking: Executor {
    // Required method
    fn spawn_blocking<F, R>(&self, f: F) -> JoinHandle<R> 
       where F: FnOnce() -> R + Send + 'static,
             R: Send + 'static;

    // Provided method
    fn spawn_blocking_abortable<F, R>(&self, f: F) -> AbortableJoinHandle<R> 
       where F: FnOnce() -> R + Send + 'static,
             R: Send + 'static { ... }
}

Required Methods§

Source

fn spawn_blocking<F, R>(&self, f: F) -> JoinHandle<R>
where F: FnOnce() -> R + Send + 'static, R: Send + 'static,

Spawn a thread in the background with the ability to concurrently await on the results without blocking the executor.

Note that there is no real way to abort the thread, and calling JoinHandle::abort would only abort the underlining tasked that is being polled but not the thread itself.

Provided Methods§

Source

fn spawn_blocking_abortable<F, R>(&self, f: F) -> AbortableJoinHandle<R>
where F: FnOnce() -> R + Send + 'static, R: Send + 'static,

Spawns a thread in the background, returning an abortable handle that will cancel it once the handle is dropped.

Note: This function is used if the task is expected to run until the handle is dropped. It is recommended to use ExecutorBlocking::spawn_blocking. Additionally, there is no guarantee that the thread will cancel or abort.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<E> ExecutorBlocking for Arc<E>

Source§

fn spawn_blocking<F, T>(&self, future: F) -> JoinHandle<T>
where F: FnOnce() -> T + Send + 'static, T: Send + 'static,

Source§

fn spawn_blocking_abortable<F, R>(&self, f: F) -> AbortableJoinHandle<R>
where F: FnOnce() -> R + Send + 'static, R: Send + 'static,

Source§

impl<E> ExecutorBlocking for Rc<E>

Source§

fn spawn_blocking<F, R>(&self, f: F) -> JoinHandle<R>
where F: FnOnce() -> R + Send + 'static, R: Send + 'static,

Implementors§