pub fn run<F>(&mut self, future: F, num_threads: usize) -> F::Output
    where
        F: Future + Send + 'static,
        F::Output: Send + 'static,
    {
        self.inner.threadiness.require_multithreaded().expect(
            "Error: called `run` on executor after using `spawn_local`. \
             Use `run_singlethreaded` instead.",
        );

        let pair = Arc::new((Mutex::new(None), Condvar::new()));
        let pair2 = pair.clone();

        // Spawn a future which will set the result upon completion.
        Inner::spawn(
            &self.inner,
            FutureObj::new(Box::new(future.then(move |fut_result| {
                let (lock, cvar) = &*pair2;
                let mut result = lock.lock();
                *result = Some(fut_result);
                cvar.notify_one();
                future::ready(())
            }))),
        );

        // Start worker threads, handing off timers from the current thread.
        self.inner.done.store(false, Ordering::SeqCst);
        with_local_timer_heap(|timer_heap| {
            let timer_heap = mem::replace(timer_heap, TimerHeap::new());
            self.create_worker_threads(num_threads, Some(timer_heap));
        });

        // Wait until the signal the future has completed.
        let (lock, cvar) = &*pair;
        let mut result = lock.lock();
        while result.is_none() {
            cvar.wait(&mut result);
        }

        // Spin down worker threads
        self.inner.done.store(true, Ordering::SeqCst);
        self.join_all();

        // Unwrap is fine because of the check to `is_none` above.
        result.take().unwrap()
    }
/// Run a single future to completion using multiple threads.
// Takes `&mut self` to ensure that only one thread-manager is running at a time.
Run a single future to completion using multiple threads.
Takes `&mut self` to ensure that only one thread-manager is running at a time.
Run a single future to completion using multiple threads . Takes ` &mut self ` to ensure that only one thread - manager is running at a time .
pub fn run<F>(&mut self, future: F, num_threads: usize) -> F::Output
    where
        F: Future + Send + 'static,
        F::Output: Send + 'static,
    {
        self.inner.threadiness.require_multithreaded().expect(
            "Error: called `run` on executor after using `spawn_local`. \
             Use `run_singlethreaded` instead.",
        );
        let pair = Arc::new((Mutex::new(None), Condvar::new()));
        let pair2 = pair.clone();
        // Spawn a future which will set the result upon completion.
        Inner::spawn(
            &self.inner,
            FutureObj::new(Box::new(future.then(move |fut_result| {
                let (lock, cvar) = &*pair2;
                let mut result = lock.lock();
                *result = Some(fut_result);
                cvar.notify_one();
                future::ready(())
            }))),
        );
        // Start worker threads, handing off timers from the current thread.
        self.inner.done.store(false, Ordering::SeqCst);
        with_local_timer_heap(|timer_heap| {
            let timer_heap = mem::replace(timer_heap, TimerHeap::new());
            self.create_worker_threads(num_threads, Some(timer_heap));
        });
        // Wait until the signal the future has completed.
        let (lock, cvar) = &*pair;
        let mut result = lock.lock();
        while result.is_none() {
            cvar.wait(&mut result);
        }
        // Spin down worker threads
        self.inner.done.store(true, Ordering::SeqCst);
        self.join_all();
        // Unwrap is fine because of the check to `is_none` above.
        result.take().unwrap()
    }
pub fn run < F > ( & mut self , future : F , num_threads : usize ) -> F :: Output where F : Future + Send + ' static , F :: Output : Send + ' static , { self . inner . threadiness . require_multithreaded ( ) . expect ( " \
 " , ) ; let pair = Arc :: new ( ( Mutex :: new ( None ) , Condvar :: new ( ) ) ) ; let pair2 = pair . clone ( ) ; // Spawn a future which will set the result upon completion. Inner :: spawn ( & self . inner , FutureObj :: new ( Box :: new ( future . then ( move | fut_result | { let ( lock , cvar ) = & * pair2 ; let mut result = lock . lock ( ) ; * result = Some ( fut_result ) ; cvar . notify_one ( ) ; future :: ready ( ( ) ) } ) ) ) , ) ; // Start worker threads, handing off timers from the current thread. self . inner . done . store ( false , Ordering :: SeqCst ) ; with_local_timer_heap ( | timer_heap | { let timer_heap = mem :: replace ( timer_heap , TimerHeap :: new ( ) ) ; self . create_worker_threads ( num_threads , Some ( timer_heap ) ) ; } ) ; // Wait until the signal the future has completed. let ( lock , cvar ) = & * pair ; let mut result = lock . lock ( ) ; while result . is_none ( ) { cvar . wait ( & mut result ) ; } // Spin down worker threads self . inner . done . store ( true , Ordering :: SeqCst ) ; self . join_all ( ) ; // Unwrap is fine because of the check to `is_none` above. result . take ( ) . unwrap ( ) }
Run a single future to completion using multiple threads.
Run a single future to completion using multiple threads .
&mut self
future
F
num_threads
usize
&mut self
future
F
num_threads
usize