pandet

version documentation

A lightweight library that helps you detect failure of spawned async tasks without having to .await their handles. Useful when you are spawning lots of detached tasks but want to fast-fail if a panic occurs.

```rust use pandet::{PanicAlert, OnPanic};

let mut alert = PanicAlert::new();

// Whichever async task spawner task::spawn( async move { panic!(); } .onpanic(&alert.newdetector()) // 👈 Binds the alert's detector );

assert!(alert.dropdetector().await.iserr()); ```

For !Send tasks, there is the UnsendOnPanic trait: ```rust use pandet::{PanicAlert, UnsendOnPanic};

let mut alert = PanicAlert::new();

task::spawnlocal( async move { panic!(); } .unsendonpanic(&alert.newdetector()) );

assert!(alert.dropdetector().await.iserr()); ```

Refined control over how to handle panics can also be implemented with PanicMonitor which works like a stream of alerts. You may also pass some information to the alert/monitor when a panic occurs: ```rust use futures::StreamExt; use pandet::{PanicMonitor, OnPanic};

// Any Unpin + Send + 'static type works struct PanicInfo { task_id: usize, }

let mut monitor = PanicMonitor::::new(); // Or simply PanicMonitor::new() { let detector = monitor.newdetector(); for taskid in 0..=10 { task::spawn( async move { if taskid % 3 == 0 { panic!(); } } // Informs the monitor of which task panicked .onpanicinfo(&detector, PanicInfo { taskid }) ); } } // detector goes out of scope, allowing the monitor to finish after calling drop_detector()

while let Some(res) = monitor.dropdetector().next().await { let info = res.unwraperr().0; asserteq!(info.taskid % 3, 0); } ```