| Crates.io | task-supervisor |
| lib.rs | task-supervisor |
| version | 0.3.5 |
| created_at | 2025-03-08 15:38:47.569392+00 |
| updated_at | 2025-12-22 20:07:16.516834+00 |
| description | Tokio tasks Supervisor |
| homepage | |
| repository | https://github.com/akhercha/task-supervisor |
| max_upload_size | |
| id | 1584610 |
| size | 80,346 |
task-supervisor helps you keep Tokio tasks alive.
It watches each task, restarts it if it crashes or stops responding, and lets you add, restart, or kill tasks at runtime.
cargo add task-supervisor
use async_trait::async_trait;
use task_supervisor::{SupervisorBuilder, SupervisedTask, TaskResult};
#[derive(Clone)]
struct Printer;
#[async_trait]
impl SupervisedTask for Printer {
async fn run(&mut self) -> TaskResult {
println!("hello");
Ok(())
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let supervisor = SupervisorBuilder::default()
.with_task("printer", Printer)
.build()
.run();
supervisor.wait().await?; // wait until every task finishes or is killed
Ok(())
}
SupervisorHandle.| TaskHandle method | Purpose |
|---|---|
add_task(name, task) |
Start a new task while running |
restart(name) |
Force a restart |
kill_task(name) |
Stop a task permanently |
get_task_status(name).await |
Return TaskStatus (Healthy, Failed, Completed, Dead, …) |
get_all_task_statuses().await |
Map of all task states |
shutdown() |
Stop every task and exit |
Full documentation lives on docs.rs.