pub struct ScopeGuard { /* private fields */ }Expand description
A scope that a value owns, which closes when the guard is dropped.
nested and nested_or_detached return this guard. Keep the guard with the value that the scope’s children
serve, so that they stop when that value is dropped.
Implementations§
Source§impl ScopeGuard
impl ScopeGuard
Sourcepub fn spawn<T>(&mut self, child: T) -> Option<ChildId>
pub fn spawn<T>(&mut self, child: T) -> Option<ChildId>
Spawns a child into the scope.
Returns the child’s ChildId, or None if the guard is detached and the child started as a detached task. A
detached child receives a shutdown signal that fires when the guard is dropped. It has no other supervision:
nothing restarts it, and nothing waits for it.
Sourcepub fn enter_sync<R>(&self, f: impl FnOnce() -> R) -> R
pub fn enter_sync<R>(&self, f: impl FnOnce() -> R) -> R
Runs f with the scope of this guard as the current scope.
Each spawn into the current scope inside f goes into this scope instead. This includes each scope that f
creates with nested_or_detached. Thus, a value that builds other values can also own their background tasks.
For example, a resolver builds its caches inside its own scope. The tasks of the caches then appear below the
resolver, and they stop when the resolver is dropped.
A detached guard has no scope, so it runs f with no change. The values that f builds then also run their
tasks detached.
Sourcepub fn is_detached(&self) -> bool
pub fn is_detached(&self) -> bool
Returns true if the guard acts as a scope outside supervision and runs its children as detached tasks.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ScopeGuard
impl RefUnwindSafe for ScopeGuard
impl Send for ScopeGuard
impl Sync for ScopeGuard
impl Unpin for ScopeGuard
impl UnsafeUnpin for ScopeGuard
impl UnwindSafe for ScopeGuard
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Track for T
impl<T> Track for T
§fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self>
fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self>
Tracked wrapper. Read more§fn in_current_resource_group(self) -> Tracked<Self>
fn in_current_resource_group(self) -> Tracked<Self>
Tracked wrapper. Read more