ShutdownTracker

Struct ShutdownTracker 

Source
pub struct ShutdownTracker { /* private fields */ }
Expand description

Extracted TaskTracker and ShutdownToken to more easily allow tracking nested tasks without having to pass whole ShutdownManager around.

Implementations§

Source§

impl ShutdownTracker

Source

pub fn spawn<F>(&self, task: F) -> JoinHandle<F::Output>
where F: Future + Send + 'static, F::Output: Send + 'static,

Spawn the provided future on the current Tokio runtime, and track it in the underlying TaskTracker.

Source

pub fn try_spawn_named<F>(&self, task: F, name: &str) -> JoinHandle<F::Output>
where F: Future + Send + 'static, F::Output: Send + 'static,

Spawn the provided future on the current Tokio runtime, and track it in the underlying TaskTracker. Furthermore, attach a name to the spawned task to more easily track it within a tokio console

Note that is no different from spawn if the underlying binary has not been built with RUSTFLAGS="--cfg tokio_unstable" and --features="tokio-tracing"

Source

pub fn spawn_on<F>(&self, task: F, handle: &Handle) -> JoinHandle<F::Output>
where F: Future + Send + 'static, F::Output: Send + 'static,

Spawn the provided future on the provided Tokio runtime, and track it in the underlying TaskTracker.

Source

pub fn spawn_local<F>(&self, task: F) -> JoinHandle<F::Output>
where F: Future + 'static, F::Output: 'static,

Spawn the provided future on the current LocalSet, and track it in the underlying TaskTracker.

Source

pub fn spawn_blocking<F, T>(&self, task: F) -> JoinHandle<T>
where F: FnOnce() -> T + Send + 'static, T: Send + 'static,

Spawn the provided blocking task on the current Tokio runtime, and track it in the underlying TaskTracker.

Source

pub fn spawn_blocking_on<F, T>(&self, task: F, handle: &Handle) -> JoinHandle<T>
where F: FnOnce() -> T + Send + 'static, T: Send + 'static,

Spawn the provided blocking task on the provided Tokio runtime, and track it in the underlying TaskTracker.

Source

pub fn try_spawn_named_with_shutdown<F>( &self, task: F, name: &str, ) -> JoinHandle<Result<F::Output, Cancelled>>
where F: Future + Send + 'static, F::Output: Send + 'static,

Spawn the provided future on the current Tokio runtime that will get cancelled once a global shutdown signal is detected, and track it in the underlying TaskTracker.

Note that to fully use the naming feature, such as tracking within a tokio console, the underlying binary has to be built with RUSTFLAGS="--cfg tokio_unstable" and --features="tokio-tracing"

Source

pub fn spawn_with_shutdown<F>( &self, task: F, ) -> JoinHandle<Result<F::Output, Cancelled>>
where F: Future + Send + 'static, F::Output: Send + 'static,

Spawn the provided future on the current Tokio runtime that will get cancelled once a global shutdown signal is detected, and track it in the underlying TaskTracker.

Source§

impl ShutdownTracker

Source

pub fn new_from_external_shutdown_token(shutdown_token: ShutdownToken) -> Self

Create new instance of the ShutdownTracker using an external shutdown token. This could be useful in situations where shutdown is being managed by an external entity that is not ShutdownManager, but interface requires providing a ShutdownTracker, such as client-core tasks

Source

pub async fn wait_for_tracker(&self)

Waits until the underlying TaskTracker is both closed and empty.

If the underlying TaskTracker is already closed and empty when this method is called, then it returns immediately.

Source

pub fn close_tracker(&self) -> bool

Close the underlying TaskTracker.

This allows wait_for_tracker futures to complete. It does not prevent you from spawning new tasks.

Returns true if this closed the underlying TaskTracker, or false if it was already closed.

Source

pub fn reopen_tracker(&self) -> bool

Reopen the underlying TaskTracker.

This prevents wait_for_tracker futures from completing even if the underlying TaskTracker is empty.

Returns true if this reopened the underlying TaskTracker, or false if it was already open.

Source

pub fn is_tracker_closed(&self) -> bool

Returns true if the underlying TaskTracker is closed.

Source

pub fn tracked_tasks(&self) -> usize

Returns the number of tasks tracked by the underlying TaskTracker.

Source

pub fn is_tracker_empty(&self) -> bool

Returns true if there are no tasks in the underlying TaskTracker.

Source

pub fn child_shutdown_token(&self) -> ShutdownToken

Obtain a ShutdownToken that is a child of the root token

Source

pub fn clone_shutdown_token(&self) -> ShutdownToken

Obtain a ShutdownToken on the same hierarchical structure as the root token

Source

pub fn child_tracker(&self) -> ShutdownTracker

Create a child ShutdownTracker that inherits cancellation from this tracker but has its own TaskTracker for managing sub-tasks.

This enables hierarchical task management where:

  • Parent cancellation flows to all children
  • Each level tracks its own tasks independently
  • Components can wait for their specific sub-tasks to complete
Source

pub async fn shutdown(self)

Convenience method to perform a complete shutdown sequence. This method:

  1. Signals cancellation to all tasks
  2. Closes the tracker to prevent new tasks
  3. Waits for all existing tasks to complete

Trait Implementations§

Source§

impl Clone for ShutdownTracker

Source§

fn clone(&self) -> ShutdownTracker

Returns a duplicate 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 ShutdownTracker

Source§

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

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

impl Default for ShutdownTracker

Source§

fn default() -> ShutdownTracker

Returns the “default value” for a 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more