pub fn run<F, R>(f: F) -> Blocking<R>
where
    F: FnOnce() -> R + Send + 'static,
    R: Send + 'static,
{
    let (tx, rx) = oneshot::channel();

    let should_spawn = {
        let mut shared = POOL.shared.lock().unwrap();

        shared.queue.push_back(Box::new(move || {
            // The receiver may have dropped
            let _ = tx.send(f());
        }));

        if shared.num_idle == 0 {
            // No threads are able to process the task

            if shared.num_th == MAX_THREADS {
                // At max number of threads
                false
            } else {
                shared.num_th += 1;
                true
            }
        } else {
            shared.num_idle -= 1;
            POOL.condvar.notify_one();
            false
        }
    };

    if should_spawn {
        spawn_thread();
    }

    Blocking { rx }
}
/// Run the provided function on a threadpool dedicated to blocking operations.
Run the provided function on a threadpool dedicated to blocking operations.
Run the provided function on a threadpool dedicated to blocking operations .
pub fn run<F, R>(f: F) -> Blocking<R>
where
    F: FnOnce() -> R + Send + 'static,
    R: Send + 'static,
{
    let (tx, rx) = oneshot::channel();
    let should_spawn = {
        let mut shared = POOL.shared.lock().unwrap();
        shared.queue.push_back(Box::new(move || {
            // The receiver may have dropped
            let _ = tx.send(f());
        }));
        if shared.num_idle == 0 {
            // No threads are able to process the task
            if shared.num_th == MAX_THREADS {
                // At max number of threads
                false
            } else {
                shared.num_th += 1;
                true
            }
        } else {
            shared.num_idle -= 1;
            POOL.condvar.notify_one();
            false
        }
    };
    if should_spawn {
        spawn_thread();
    }
    Blocking { rx }
}
pub fn run < F , R > ( f : F ) -> Blocking < R > where F : FnOnce ( ) -> R + Send + ' static , R : Send + ' static , { let ( tx , rx ) = oneshot :: channel ( ) ; let should_spawn = { let mut shared = POOL . shared . lock ( ) . unwrap ( ) ; shared . queue . push_back ( Box :: new ( move | | { // The receiver may have dropped let _ = tx . send ( f ( ) ) ; } ) ) ; if shared . num_idle == 0 { // No threads are able to process the task if shared . num_th == MAX_THREADS { // At max number of threads false } else { shared . num_th += 1 ; true } } else { shared . num_idle -= 1 ; POOL . condvar . notify_one ( ) ; false } } ; if should_spawn { spawn_thread ( ) ; } Blocking { rx } }
Run the provided function on a threadpool dedicated to blocking operations.
Run the provided function on a threadpool dedicated to blocking operations .
f
F
f
F