Expand description
Task group for managing background tasks with graceful shutdown.
This module provides a TaskGroup that tracks spawned tasks and allows
for coordinated shutdown with timeout handling.
§Example
ⓘ
use crate::shared::task_group::TaskGroup;
use crate::shared::shutdown::Shutdown;
use std::time::Duration;
let shutdown = Shutdown::new();
let mut group = TaskGroup::new();
// Spawn a task that respects shutdown
let mut shutdown_rx = shutdown.subscribe();
group.spawn("MyTask", async move {
loop {
tokio::select! {
_ = shutdown_rx.recv() => break,
// ... do work
}
}
Ok(())
});
// Later, shutdown all tasks
group.shutdown_and_join(&shutdown, Duration::from_secs(5)).await?;Structs§
- Task
Group - A group of background tasks that can be shut down together.
- Task
Handle 🔒 - A handle to a spawned background task.