Skip to content

Commit

Permalink
Reduce verbosity in example; name toplevel task
Browse files Browse the repository at this point in the history
  • Loading branch information
Finomnis committed Nov 2, 2024
1 parent 7e7ce65 commit f25f8fe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 7 additions & 2 deletions examples/tokio_console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
use miette::Result;
use tokio::time::{sleep, Duration};
use tokio_graceful_shutdown::{FutureExt, SubsystemBuilder, SubsystemHandle, Toplevel};
use tracing_subscriber::prelude::*;
use tracing::Level;
use tracing_subscriber::{fmt::writer::MakeWriterExt, prelude::*};

async fn child(subsys: SubsystemHandle) -> Result<()> {
sleep(Duration::from_millis(3000))
Expand Down Expand Up @@ -47,7 +48,11 @@ async fn main() -> Result<()> {
let console_layer = console_subscriber::spawn();
tracing_subscriber::registry()
.with(console_layer)
.with(tracing_subscriber::fmt::layer().compact())
.with(
tracing_subscriber::fmt::layer()
.with_writer(std::io::stdout.with_max_level(Level::DEBUG))
.compact(),
)
.init();

// Setup and execute subsystem tree
Expand Down
6 changes: 5 additions & 1 deletion src/subsystem/subsystem_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ impl<ErrType: ErrTypeTraits> SubsystemHandle<ErrType> {
Err: Into<ErrType>,
{
self.start_with_abs_name(
Arc::from(format!("{}/{}", self.inner.name, builder.name)),
if self.inner.name.as_ref() == "/" {
Arc::from(format!("/{}", builder.name))
} else {
Arc::from(format!("{}/{}", self.inner.name, builder.name))
},
builder.subsystem,
ErrorActions {
on_failure: Atomic::new(builder.failure_action),
Expand Down
2 changes: 1 addition & 1 deletion src/toplevel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<ErrType: ErrTypeTraits> Toplevel<ErrType> {
});

let toplevel_subsys = root_handle.start_with_abs_name(
Arc::from(""),
Arc::from("/"),
move |s| async move {
subsystem(s).await;
Result::<(), ErrType>::Ok(())
Expand Down

0 comments on commit f25f8fe

Please sign in to comment.