use std::time::Duration;
use await_tree::{span, Config, InstrumentAwait, Registry};
use futures::future::pending;
use itertools::Itertools;
use tokio::time::sleep;
async fn work(i: i32) {
foo().instrument_await(span!("actor work {i}")).await
}
async fn foo() {
pending().instrument_await("pending").await
}
#[tokio::main]
async fn main() {
let registry = Registry::new(Config::default());
for i in 0_i32..3 {
let root = registry.register(i, format!("actor {i}"));
tokio::spawn(root.instrument(work(i)));
}
sleep(Duration::from_secs(1)).await;
for (_, tree) in registry
.collect::<i32>()
.into_iter()
.sorted_by_key(|(i, _)| *i)
{
println!("{tree}");
}
}