| Crates.io | tokio-task-supervisor |
| lib.rs | tokio-task-supervisor |
| version | 0.1.1 |
| created_at | 2025-10-12 03:15:10.971994+00 |
| updated_at | 2025-10-12 18:58:42.484165+00 |
| description | Tokio TaskTracker with built-in cancellation token management and coordinated shutdown. |
| homepage | |
| repository | https://github.com/juliuslipp/tokio-task-supervisor |
| max_upload_size | |
| id | 1878818 |
| size | 37,721 |
A wrapper around tokio_util::task::TaskTracker that adds coordinated shutdown via a shared cancellation token.
TaskTracker)CancellationToken for shutdownuse tokio_task_supervisor::TaskSupervisor;
use tokio::time::{sleep, Duration};
#[tokio::main]
async fn main() {
let supervisor = TaskSupervisor::new();
// Spawn tasks that can be cancelled
let handle = supervisor.spawn_with_token(|token| async move {
loop {
tokio::select! {
_ = token.cancelled() => break,
_ = sleep(Duration::from_millis(100)) => {}
}
}
});
// Shutdown all tasks
supervisor.shutdown().await;
handle.await.expect("task finished");
}
spawn_with_token() - spawn task with cancellation tokenspawn_with_cancel() - spawn task that races against cancellationshutdown() - cancel all tasks and wait for completionMIT