MCPcopy Create free account
hub / github.com/NthTensor/Forte / Spawn

Interface Spawn

src/thread_pool.rs:466–485  ·  view source on GitHub ↗

A trait for types that can be spawned onto a [`ThreadPool`]. It is implemented for: Closures that satisfy `for<'worker> FnOnce(&'worker Worker) + Send + 'static`. Futures that satisfy `Future + Send + 'static` where `T: Send + 'static`. Closures return `()` when spawned, but futures return a [`Task`]. # Compile Errors Due to a bug in rustc, you may be given errors when using clos

Source from the content-addressed store, hash-verified

464 Some(worker) if worker.thread_pool.id() == self.id() => {
465 func(Some(worker))
466 }
467 _ => func(None),
468 })
469 }
470
471 /// Returns this thread's worker. If not already a member of this thread
472 /// pool, this thread will try to enroll itself as a member.
473 ///
474 /// Note: If the thread pool is full (it already has 32 active members) this
475 /// waits for a vacancy before returning.
476 ///
477 /// # Panics
478 ///
479 /// Panics that propagate out of the closure may cause aborts, if this call
480 /// registered this thread as a temporary member of the pool.
481 #[inline(always)]
482 pub fn with_worker<F, R>(&'static self, func: F) -> R
483 where
484 F: FnOnce(&Worker) -> R,
485 {
486 self.get_worker(|worker| match worker {
487 Some(worker) => func(worker),
488 None => self.with_worker_cold(func),

Callers

nothing calls this directly

Implementers 1

thread_pool.rssrc/thread_pool.rs

Calls

no outgoing calls

Tested by

no test coverage detected