pub struct WorkersPool<W: Worker> { /* private fields */ }Expand description
Abstraction of a threadpool for executing units of computation in parallel.
Implementations§
Source§impl<W: Worker> WorkersPool<W>
impl<W: Worker> WorkersPool<W>
pub fn new(context: W::Context) -> Self
Sourcepub fn add_work(&mut self, work: W::Data) -> Result<(), ()>
pub fn add_work(&mut self, work: W::Data) -> Result<(), ()>
Adds work to be executed on one of the threads of this pool This function is non-blocking
Sourcepub fn receive_result(&mut self) -> Result<W::Result, ()>
pub fn receive_result(&mut self) -> Result<W::Result, ()>
Receives the result of a computation This function blocks until a result is available or all threads have panicked
Sourcepub fn try_receive_result(&mut self) -> Result<Option<W::Result>, ()>
pub fn try_receive_result(&mut self) -> Result<Option<W::Result>, ()>
Tries to receive the result of a computation This function does not block if no result is available but rather returns Ok(None)
Sourcepub fn collect_finished(&mut self) -> Result<Vec<W::Result>, ()>
pub fn collect_finished(&mut self) -> Result<Vec<W::Result>, ()>
Collects all available results
Sourcepub fn has_work_left(&self) -> bool
pub fn has_work_left(&self) -> bool
Checks if any work is left in the work queue
Note: An empty work queue does not mean that none of the worker threads is still busy
Sourcepub fn has_results(&self) -> bool
pub fn has_results(&self) -> bool
Checks if there are results available
Auto Trait Implementations§
impl<W> Freeze for WorkersPool<W>
impl<W> !RefUnwindSafe for WorkersPool<W>
impl<W> Send for WorkersPool<W>
impl<W> Sync for WorkersPool<W>
impl<W> Unpin for WorkersPool<W>
impl<W> !UnwindSafe for WorkersPool<W>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more