pub struct Pool(/* private fields */);
Expand description
A Pool
object represents a private thread pool with its own thread limits.
This is in contrast to the default, or shared, thread pool used by the crate’s submit
function
as well as other code within the same process.
Implementations§
Source§impl Pool
impl Pool
Sourcepub fn with_scope<'env, F>(f: F)
pub fn with_scope<'env, F>(f: F)
Convenience function for creating a new pool and calling scope
.
Sourcepub fn set_thread_limits(&self, min: u32, max: u32)
pub fn set_thread_limits(&self, min: u32, max: u32)
Sets the thread limits for the Pool
object.
Sourcepub fn submit<F: FnOnce() + Send + 'static>(&self, f: F)
pub fn submit<F: FnOnce() + Send + 'static>(&self, f: F)
Submit the closure to the thread pool.
- The closure must have
'static
lifetime as the thread may outlive the lifetime in whichsubmit
is called. - The closure must be
Send
as it will be sent to another thread for execution.
Sourcepub fn scope<'env, F>(&self, f: F)
pub fn scope<'env, F>(&self, f: F)
Create a scope for submitting closures.
Within this scope local variables can be sent to the pool thread for execution.
This is possible because scope
will wait for all submitted closures to finish before returning,
Note however that it will also wait for closures that were submitted from other threads.
Trait Implementations§
Auto Trait Implementations§
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