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
impl ShutdownTracker
Sourcepub fn spawn<F>(&self, task: F) -> JoinHandle<F::Output>
pub fn spawn<F>(&self, task: F) -> JoinHandle<F::Output>
Spawn the provided future on the current Tokio runtime, and track it in the underlying TaskTracker.
Sourcepub fn try_spawn_named<F>(&self, task: F, name: &str) -> JoinHandle<F::Output>
pub fn try_spawn_named<F>(&self, task: F, name: &str) -> JoinHandle<F::Output>
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"
Sourcepub fn spawn_on<F>(&self, task: F, handle: &Handle) -> JoinHandle<F::Output>
pub fn spawn_on<F>(&self, task: F, handle: &Handle) -> JoinHandle<F::Output>
Spawn the provided future on the provided Tokio runtime, and track it in the underlying TaskTracker.
Sourcepub fn spawn_local<F>(&self, task: F) -> JoinHandle<F::Output>
pub fn spawn_local<F>(&self, task: F) -> JoinHandle<F::Output>
Spawn the provided future on the current LocalSet, and track it in the underlying TaskTracker.
Sourcepub fn spawn_blocking<F, T>(&self, task: F) -> JoinHandle<T>
pub fn spawn_blocking<F, T>(&self, task: F) -> JoinHandle<T>
Spawn the provided blocking task on the current Tokio runtime, and track it in the underlying TaskTracker.
Sourcepub fn spawn_blocking_on<F, T>(&self, task: F, handle: &Handle) -> JoinHandle<T>
pub fn spawn_blocking_on<F, T>(&self, task: F, handle: &Handle) -> JoinHandle<T>
Spawn the provided blocking task on the provided Tokio runtime, and track it in the underlying TaskTracker.
Sourcepub fn try_spawn_named_with_shutdown<F>(
&self,
task: F,
name: &str,
) -> JoinHandle<Result<F::Output, Cancelled>>
pub fn try_spawn_named_with_shutdown<F>( &self, task: F, name: &str, ) -> JoinHandle<Result<F::Output, Cancelled>>
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"
Sourcepub fn spawn_with_shutdown<F>(
&self,
task: F,
) -> JoinHandle<Result<F::Output, Cancelled>>
pub fn spawn_with_shutdown<F>( &self, task: F, ) -> JoinHandle<Result<F::Output, Cancelled>>
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
impl ShutdownTracker
Sourcepub fn new_from_external_shutdown_token(shutdown_token: ShutdownToken) -> Self
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
Sourcepub async fn wait_for_tracker(&self)
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.
Sourcepub fn close_tracker(&self) -> bool
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.
Sourcepub fn reopen_tracker(&self) -> bool
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.
Sourcepub fn is_tracker_closed(&self) -> bool
pub fn is_tracker_closed(&self) -> bool
Returns true if the underlying TaskTracker is closed.
Sourcepub fn tracked_tasks(&self) -> usize
pub fn tracked_tasks(&self) -> usize
Returns the number of tasks tracked by the underlying TaskTracker.
Sourcepub fn is_tracker_empty(&self) -> bool
pub fn is_tracker_empty(&self) -> bool
Returns true if there are no tasks in the underlying TaskTracker.
Sourcepub fn child_shutdown_token(&self) -> ShutdownToken
pub fn child_shutdown_token(&self) -> ShutdownToken
Obtain a ShutdownToken that is a child of the root token
Sourcepub fn clone_shutdown_token(&self) -> ShutdownToken
pub fn clone_shutdown_token(&self) -> ShutdownToken
Obtain a ShutdownToken on the same hierarchical structure as the root token
Sourcepub fn child_tracker(&self) -> ShutdownTracker
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
Trait Implementations§
Source§impl Clone for ShutdownTracker
impl Clone for ShutdownTracker
Source§fn clone(&self) -> ShutdownTracker
fn clone(&self) -> ShutdownTracker
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more