Skip to main content

ThreadScopeExt

Trait ThreadScopeExt 

pub trait ThreadScopeExt<'scope> {
    // Required method
    fn spawn_with_priority<F, T>(
        &'scope self,
        priority: ThreadPriority,
        f: F,
    ) -> ScopedJoinHandle<'scope, T>
       where F: FnOnce(Result<(), Error>) -> T + Send + 'scope,
             T: Send + 'scope;
}
Expand description

Adds scoped thread building functions using the priority.

Required Methods§

fn spawn_with_priority<F, T>( &'scope self, priority: ThreadPriority, f: F, ) -> ScopedJoinHandle<'scope, T>
where F: FnOnce(Result<(), Error>) -> T + Send + 'scope, T: Send + 'scope,

Spawn a scoped thread with set priority. The passed functor f is executed in the spawned thread and receives as the only argument the result of setting the thread priority. See std::thread::Scope::spawn and ThreadPriority::set_for_current for more info.

§Example
use thread_priority::*;

let x = 0;

std::thread::scope(|s|{
    s.spawn_with_priority(ThreadPriority::Max, |result| {
            // This is printed out from within the spawned thread.
            println!("Set priority result: {:?}", result);
            assert!(result.is_ok());
            dbg!(&x);
    });
});

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

§

impl<'scope> ThreadScopeExt<'scope> for Scope<'scope, '_>

§

fn spawn_with_priority<F, T>( &'scope self, priority: ThreadPriority, f: F, ) -> ScopedJoinHandle<'scope, T>
where F: FnOnce(Result<(), Error>) -> T + Send + 'scope, T: Send + 'scope,

Implementors§