scoped_pool

Struct Scope

Source
pub struct Scope<'scope> { /* private fields */ }
Expand description

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).

Implementations§

Source§

impl<'scope> Scope<'scope>

Source

pub fn forever(pool: Pool) -> Scope<'static>

Create a Scope which lasts forever.

Source

pub fn execute<F>(&self, job: F)
where F: FnOnce() + Send + 'scope,

Add a job to this scope.

Subsequent calls to join will wait for this job to complete.

Source

pub fn recurse<F>(&self, job: F)
where 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.

Source

pub fn zoom<'smaller, F, R>(&self, scheduler: F) -> R
where 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.

Source

pub fn join(&self)

Awaits all jobs submitted on this Scope to be completed.

Only guaranteed to join jobs which where executed logically prior to join. Jobs executed concurrently with join may or may not be completed before join returns.

Auto Trait Implementations§

§

impl<'scope> Freeze for Scope<'scope>

§

impl<'scope> !RefUnwindSafe for Scope<'scope>

§

impl<'scope> Send for Scope<'scope>

§

impl<'scope> Sync for Scope<'scope>

§

impl<'scope> Unpin for Scope<'scope>

§

impl<'scope> !UnwindSafe for Scope<'scope>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.