Skip to main content

Module task_group

Module task_group 

Source
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§

TaskGroup
A group of background tasks that can be shut down together.
TaskHandle 🔒
A handle to a spawned background task.