1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

#![allow(unused_imports)]

use picollar::local;

use picollar::tasktrack::Tracker;

use tokio::time;
use tokio::time::Duration;

use anyhow::anyhow;

#[tokio::main(core_threads=1)]
async fn main(){
  let mut tt = Tracker::new();
  tt.spawn("panicer", async {
    eprintln!("panicer started");
    time::delay_for(Duration::from_millis(1000)).await;
    eprintln!("panicer about to panic!");
    panic!("eep!");
  });
  tt.spawn("ender", async {
    eprintln!("ender started");
    time::delay_for(Duration::from_millis(4000)).await;
    eprintln!("ender exiting");
    Ok(())
  });
  tt.spawn("failer", async {
    eprintln!("ender started");
    time::delay_for(Duration::from_millis(3000)).await;
    eprintln!("failer exiting");
    Err(anyhow!("yikes!"))
  });
  eprintln!("main spawned");
  time::delay_for(Duration::from_millis(2000)).await;
  eprintln!("main ending");

  tt.failfast().await.expect("at end");
}