pub struct TaskCounter { /* private fields */ }Expand description
Tracks the number of active background tasks. reset() cancels the token
then calls wait_for_zero() to ensure all tasks have exited before clearing
shared state.
Implementations§
Source§impl TaskCounter
impl TaskCounter
pub fn new() -> Arc<Self> ⓘ
Sourcepub async fn wait_for_zero(self: &Arc<Self>)
pub async fn wait_for_zero(self: &Arc<Self>)
Wait until the active task count reaches zero.
Sourcepub fn guard(self: &Arc<Self>) -> TaskGuard
pub fn guard(self: &Arc<Self>) -> TaskGuard
Create a guard that increments the counter now and decrements on drop.
Sourcepub fn try_guard(self: &Arc<Self>) -> Option<TaskGuard>
pub fn try_guard(self: &Arc<Self>) -> Option<TaskGuard>
Admit a new top-level operation unless reset has paused admission.
A second acceptance check closes the race with Self::try_pause.
Sourcepub fn try_pause(self: &Arc<Self>) -> Option<TaskCounterPause>
pub fn try_pause(self: &Arc<Self>) -> Option<TaskCounterPause>
Stop admitting top-level operations until the returned guard is dropped.
Returns None when another reset already owns the pause.
Auto Trait Implementations§
impl !Freeze for TaskCounter
impl Forget for TaskCounter
impl Move for TaskCounter
impl RefUnwindSafe for TaskCounter
impl Send for TaskCounter
impl Sync for TaskCounter
impl Unpin for TaskCounter
impl UnsafeUnpin for TaskCounter
impl UnwindSafe for TaskCounter
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
Mutably borrows from an owned value. Read more
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> 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> ⓘ
Converts
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> ⓘ
Converts
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 moreSource§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>
Wrap the input message
T in a tonic::Request