Struct scoped_pool::Scope
[−]
[src]
pub struct Scope<'scope> { /* fields omitted */ }
An execution scope, represents a set of jobs running on a Pool.
Understanding Scope lifetimes
Besides Scope<'static>
, all Scope
objects are accessed behind a
reference of the form &'scheduler Scope<'scope>
.
'scheduler
is the lifetime associated with the body of the
"scheduler" function (functions passed to zoom
/scoped
).
'scope
is the lifetime which data captured in execute
or recurse
closures must outlive - in other words, 'scope
is the maximum lifetime
of all jobs scheduler on a Scope
.
Note that since 'scope: 'scheduler
('scope
outlives 'scheduler
)
&'scheduler Scope<'scope>
can't be captured in an execute
closure;
this is the reason for the existence of the recurse
API, which will
inject the same scope with a new 'scheduler
lifetime (this time set
to the body of the function passed to recurse
).
Methods
impl<'scope> Scope<'scope>
[src]
fn forever(pool: Pool) -> Scope<'static>
Create a Scope which lasts forever.
fn execute<F>(&self, job: F) where
F: FnOnce() + Send + 'scope,
F: FnOnce() + Send + 'scope,
Add a job to this scope.
Subsequent calls to join
will wait for this job to complete.
fn recurse<F>(&self, job: F) where
F: FnOnce(&Self) + Send + 'scope,
F: FnOnce(&Self) + Send + 'scope,
Add a job to this scope which itself will get access to the scope.
Like with execute
, subsequent calls to join
will wait for this
job (and all jobs scheduled on the scope it receives) to complete.
fn zoom<'smaller, F, R>(&self, scheduler: F) -> R where
F: FnOnce(&Scope<'smaller>) -> R,
'scope: 'smaller,
F: FnOnce(&Scope<'smaller>) -> R,
'scope: 'smaller,
Create a new subscope, bound to a lifetime smaller than our existing Scope.
The subscope has a different job set, and is joined before zoom returns.
fn join(&self)
Awaits all jobs submitted on this Scope to be completed.
Only guaranteed to join jobs which where execute
d logically
prior to join
. Jobs execute
d concurrently with join
may
or may not be completed before join
returns.