Struct ScopeActiveGuard

Source
pub struct ScopeActiveGuard(/* private fields */);
Expand description

Holds a guard on the creating scope, holding off cancelation.

ScopeActiveGuard allows Scopes to perform cooperative cancellation. ScopeActiveGuard::on_cancel returns a future that resolves when Scope::cancel and ScopeHandle::cancel are called. That is the signal sent to cooperative tasks to stop doing work and finish.

A ScopeActiveGuard is obtained via ScopeHandle::active_guard. ScopeActiveGuard releases the guard on the originating scope on drop.

Implementations§

Source§

impl ScopeActiveGuard

Source

pub fn as_handle(&self) -> &ScopeHandle

Returns a borrow of the scope handle associated with this guard.

Source

pub fn to_handle(&self) -> ScopeHandle

Returns a clone of the scope handle associated with this guard.

Source

pub async fn on_cancel(&self)

Retrieves a future from this guard that can be polled on for cancellation.

The returned future resolves when the scope is cancelled. Callers should perform teardown and drop the guard when done.

Methods from Deref<Target = ScopeHandle>§

Source

pub fn new_child(&self) -> Scope

Create a child scope.

Source

pub fn new_child_with_name(&self, name: impl Into<String>) -> Scope

Create a child scope.

Source

pub fn spawn(&self, future: impl Spawnable<Output = ()>) -> JoinHandle<()>

Spawn a new task on the scope.

Source

pub fn spawn_local( &self, future: impl Future<Output = ()> + 'static, ) -> JoinHandle<()>

Spawn a new task on the scope of a thread local executor.

NOTE: This is not supported with a SendExecutor and will cause a runtime panic. Use ScopeHandle::spawn instead.

Source

pub fn compute<T: Send + 'static>( &self, future: impl Spawnable<Output = T> + Send + 'static, ) -> Task<T>

Like spawn, but for tasks that return a result.

NOTE: Unlike spawn, when tasks are dropped, the future will be cancelled.

Source

pub fn compute_local<T: 'static>( &self, future: impl Future<Output = T> + 'static, ) -> Task<T>

Like spawn, but for tasks that return a result.

NOTE: Unlike spawn, when tasks are dropped, the future will be cancelled.

NOTE: This is not supported with a SendExecutor and will cause a runtime panic. Use ScopeHandle::spawn instead.

Source

pub fn close(&self)

Stop the scope from accepting new tasks.

Note that unlike Scope::close, this does not return a future that waits for all tasks to complete. This could lead to resource leaks because it is not uncommon to access a TaskGroup from a task running on the scope itself. If such a task were to await a future returned by this method it would suspend forever waiting for itself to complete.

Source

pub fn active_guard(&self) -> Option<ScopeActiveGuard>

Retrieves a ScopeActiveGuard for this scope.

Note that this may fail if cancellation has already started for this scope. In that case, the caller must assume any tasks from this scope may be dropped at any yield point.

Creating a ScopeActiveGuard is substantially more expensive than just polling it, so callers should maintain the returned guard when success is observed from this call for best performance.

See Scope::cancel for details on cooperative cancellation behavior.

Source

pub fn is_cancelled(&self) -> bool

Returns true if the scope has been signaled to exit via Scope::cancel or Scope::abort.

Source

pub async fn on_no_tasks(&self)

Wait for there to be no tasks. This is racy: as soon as this returns it is possible for another task to have been spawned on this scope.

Source

pub fn wake_all(&self)

Wake all the scope’s tasks so their futures will be polled again.

Trait Implementations§

Source§

impl Clone for ScopeActiveGuard

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ScopeActiveGuard

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for ScopeActiveGuard

Source§

type Target = ScopeHandle

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Drop for ScopeActiveGuard

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.