use std::time::Duration;
use await_tree::{Config, InstrumentAwait, Registry, SpanExt};
use futures::future::{pending, select};
use futures::FutureExt;
use tokio::time::sleep;
async fn long_running_child() {
pending()
.instrument_await("long_running_child".long_running())
.await
}
async fn child() {
pending().instrument_await("child").await
}
async fn foo() {
select(long_running_child().boxed(), child().boxed()).await;
}
async fn work() -> String {
let registry = Registry::new(Config::default());
let root = registry.register((), "foo");
tokio::spawn(root.instrument(foo()));
sleep(Duration::from_secs(11)).await;
registry.get(()).unwrap().to_string()
}
#[tokio::main]
async fn main() {
println!("{}", work().await);
}