pub struct ActiveGuard(/* private fields */);
Expand description
Holds a guard on the creating scope, holding off cancelation.
ScopeActiveGuard
allows Scope
s 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
impl ScopeActiveGuard
Sourcepub fn as_handle(&self) -> &ScopeHandle
pub fn as_handle(&self) -> &ScopeHandle
Returns a borrow of the scope handle associated with this guard.
Sourcepub fn to_handle(&self) -> ScopeHandle
pub fn to_handle(&self) -> ScopeHandle
Returns a clone of the scope handle associated with this guard.
Methods from Deref<Target = ScopeHandle>§
Sourcepub fn new_child_with_name(&self, name: impl Into<String>) -> Scope
pub fn new_child_with_name(&self, name: impl Into<String>) -> Scope
Create a child scope.
Sourcepub fn spawn(&self, future: impl Spawnable<Output = ()>) -> JoinHandle<()>
pub fn spawn(&self, future: impl Spawnable<Output = ()>) -> JoinHandle<()>
Spawn a new task on the scope.
Sourcepub fn spawn_local(
&self,
future: impl Future<Output = ()> + 'static,
) -> JoinHandle<()>
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.
Sourcepub fn compute<T>(
&self,
future: impl Spawnable<Output = T> + Send + 'static,
) -> Task<T>where
T: Send + 'static,
pub fn compute<T>(
&self,
future: impl Spawnable<Output = T> + Send + 'static,
) -> Task<T>where
T: Send + 'static,
Like spawn
, but for tasks that return a result.
NOTE: Unlike spawn
, when tasks are dropped, the future will be
cancelled.
Sourcepub fn compute_local<T>(
&self,
future: impl Future<Output = T> + 'static,
) -> Task<T>where
T: 'static,
pub fn compute_local<T>(
&self,
future: impl Future<Output = T> + 'static,
) -> Task<T>where
T: 'static,
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.
Sourcepub fn close(&self)
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.
Sourcepub fn active_guard(&self) -> Option<ScopeActiveGuard>
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.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Returns true if the scope has been signaled to exit via
Scope::cancel
or Scope::abort
.
Sourcepub async fn on_no_tasks(&self)
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.
Sourcepub async fn on_no_tasks_and_guards(&self)
pub async fn on_no_tasks_and_guards(&self)
Wait for there to be no tasks and no guards. This is racy: as soon as this returns it is possible for another task to have been spawned on this scope, or for there to be guards.
Sourcepub fn wake_all_with_active_guard(&self)
pub fn wake_all_with_active_guard(&self)
Wake all the scope’s tasks so their futures will be polled again.
Trait Implementations§
Source§impl Clone for ScopeActiveGuard
impl Clone for ScopeActiveGuard
Source§fn clone(&self) -> ScopeActiveGuard
fn clone(&self) -> ScopeActiveGuard
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for ScopeActiveGuard
impl Debug for ScopeActiveGuard
Source§impl Deref for ScopeActiveGuard
impl Deref for ScopeActiveGuard
Source§type Target = ScopeHandle
type Target = ScopeHandle
Auto Trait Implementations§
impl Freeze for ScopeActiveGuard
impl !RefUnwindSafe for ScopeActiveGuard
impl Send for ScopeActiveGuard
impl Sync for ScopeActiveGuard
impl Unpin for ScopeActiveGuard
impl !UnwindSafe for ScopeActiveGuard
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
Source§impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more