use std::{io, process::ExitCode, time::Duration};
use tracing::level_filters::LevelFilter;
use tracing_subscriber::{EnvFilter, Layer, fmt, layer::SubscriberExt, util::SubscriberInitExt};
#[derive(Debug, thiserror::Error, miette::Diagnostic)]
#[error("Error type 0: {0}")]
struct Error0(&'static str);
#[derive(Debug, thiserror::Error, miette::Diagnostic)]
#[error("Error type 1: {0}")]
struct Error1(&'static str);
#[derive(Debug, thiserror::Error, miette::Diagnostic)]
#[error("Error type 2: {0}")]
struct Error2(&'static str);
#[tokio::main]
async fn main() -> miette::Result<ExitCode> {
tracing_subscriber::registry()
.with(
fmt::Layer::new().with_writer(io::stderr).with_filter(
EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy(),
),
)
.init();
tosub::build_root("hello_world")
.catch_signals()
.with_timeout(Duration::from_secs(5))
.start(run)
.await
}
async fn run(root: tosub::Subsystem) -> Result<(), Error0> {
root.spawn("child 1", |_| async { Err::<(), Error1>(Error1("some")) });
root.spawn("child 2", |_| async { Err::<(), Error2>(Error2("thing")) });
Ok(())
}