1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2025 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
//! A [CancellationToken](tokio_util::sync::CancellationToken)-backed shutdown mechanism for Nym binaries.
//!
//! It allows creation of a centralised manager for keeping track of all signals that are meant
//! to trigger exit of all associated tasks and sending cancellation to the aforementioned futures.
//!
//! # Default usage
//!
//! ```no_run
//! use std::time::Duration;
//! use tokio::time::sleep;
//! use nym_task::{ShutdownManager, ShutdownToken};
//!
//! async fn my_task() {
//! loop {
//! sleep(Duration::from_secs(5)).await
//! // do some periodic work that can be easily interrupted
//! }
//! }
//!
//! async fn important_work_that_cant_be_interrupted() {}
//!
//! async fn my_managed_task(shutdown_token: ShutdownToken) {
//! tokio::select! {
//! _ = shutdown_token.cancelled() => {}
//! _ = important_work_that_cant_be_interrupted() => {}
//! }
//! }
//! #[tokio::main]
//! async fn main() {
//! let mut shutdown_manager = ShutdownManager::build_new_default().expect("failed to register default shutdown signals");
//!
//! let shutdown_token = shutdown_manager.child_shutdown_token();
//! shutdown_manager.try_spawn_named(async move { my_managed_task(shutdown_token).await }, "important-managed-task");
//! shutdown_manager.try_spawn_named_with_shutdown(my_task(), "another-task");
//!
//! // wait for shutdown signal
//! shutdown_manager.run_until_shutdown().await;
//! }
//! ```
use Duration;
pub use ShutdownManager;
pub use ;
pub use ShutdownTracker;
pub const DEFAULT_MAX_SHUTDOWN_DURATION: Duration = from_secs;