pub struct Scope<'pool, 'scope> { /* private fields */ }
Expand description
Represents the current scope, you can execute functions in it.
Implementations
sourceimpl<'pool, 'scope> Scope<'pool, 'scope>
impl<'pool, 'scope> Scope<'pool, 'scope>
sourcepub fn with_state<StateMaker, State>(
self,
state_maker: StateMaker
) -> ScopeWithState<'pool, 'scope, State>where
StateMaker: Fn() -> State + Send + 'scope,
State: 'static,
pub fn with_state<StateMaker, State>(
self,
state_maker: StateMaker
) -> ScopeWithState<'pool, 'scope, State>where
StateMaker: Fn() -> State + Send + 'scope,
State: 'static,
Give each of the threads a state
The parameter is a closure that is run in each thread. The parameter finishes running before this function exits.
A new scope is returned that allows one to run jobs in the worker threads which can take the state parameter.
sourcepub fn execute<F>(&self, f: F)where
F: FnOnce() + Send + 'scope,
pub fn execute<F>(&self, f: F)where
F: FnOnce() + Send + 'scope,
Execute a job on one of the threads in the threadpool.
The closure is called from one of the threads. If the threadpool has a specified backlog, then this function blocks until the threadpool finishes a job.
This function may panic if a job that was previously
execute
d has panicked. This way, your program terminates
as soon as a panic occurs. If you don’t call this function
again after a panic occurs, then Pool::scoped
will panic before it completes.