Skip to content

Commit

Permalink
Minor refactoring in example
Browse files Browse the repository at this point in the history
  • Loading branch information
Finomnis committed Nov 2, 2024
1 parent 337b99a commit 69c92ec
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions examples/tokio_console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ use tokio::time::{sleep, Duration};
use tokio_graceful_shutdown::{FutureExt, SubsystemBuilder, SubsystemHandle, Toplevel};
use tracing_subscriber::prelude::*;

async fn subsys(subsys: SubsystemHandle) -> Result<()> {
async fn child(subsys: SubsystemHandle) -> Result<()> {
sleep(Duration::from_millis(3000))
.cancel_on_shutdown(&subsys)
.await
.ok();
Ok(())
}

async fn parent(subsys: SubsystemHandle) -> Result<()> {
tracing::info!("Parent started.");

let mut iteration = 0;
Expand All @@ -33,26 +41,18 @@ async fn subsys(subsys: SubsystemHandle) -> Result<()> {
Ok(())
}

async fn child(subsys: SubsystemHandle) -> Result<()> {
sleep(Duration::from_millis(3000))
.cancel_on_shutdown(&subsys)
.await
.ok();
Ok(())
}

#[tokio::main]
async fn main() -> Result<()> {
// Init tokio-console server and tracing
let console_layer = console_subscriber::spawn();
// Init logging
tracing_subscriber::registry()
.with(console_layer)
.with(tracing_subscriber::fmt::layer().compact())
.init();

// Setup and execute subsystem tree
Toplevel::new(|s| async move {
s.start(SubsystemBuilder::new("parent", subsys));
s.start(SubsystemBuilder::new("parent", parent));
})
.catch_signals()
.handle_shutdown_requests(Duration::from_millis(1000))
Expand Down

0 comments on commit 69c92ec

Please sign in to comment.