expression
TaskTracker close and wait
Track task lifetimes until the tracker is closed and empty. Closing permits wait to complete when empty; it does not prevent spawning additional tasks. Stop accepting work through a separate policy, and keep join handles if individual failures or results matter. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): true 8 Common mistake: Expecting close() to reject every new task or cancel existing tasks.
Formal Syntax & Structure
rust syntaxrust
TaskTracker::new(); spawn; close; waitWorking Example
Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() { use tokio_util::task::TaskTracker; let tracker = TaskTracker::new(); let a = tracker.spawn(async { 3u32 }); let b = tracker.spawn(async { 5u32 }); tracker.close(); tracker.wait().await; println!("{} {}", tracker.is_empty(), a.await.unwrap() + b.await.unwrap());}