-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//! This example shows how to use this library with eyre instead of anyhow | ||
use env_logger::{Builder, Env}; | ||
use eyre::{eyre, Result}; | ||
use tokio::time::{sleep, Duration}; | ||
use tokio_graceful_shutdown::{SubsystemHandle, Toplevel}; | ||
|
||
async fn subsys1(_subsys: SubsystemHandle) -> Result<()> { | ||
log::info!("Subsystem1 started."); | ||
sleep(Duration::from_millis(500)).await; | ||
log::info!("Subsystem1 stopped."); | ||
|
||
// Task ends with an error. This should cause the main program to shutdown. | ||
Err(eyre!("Subsystem1 threw an error.")) | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
// Init logging | ||
Builder::from_env(Env::default().default_filter_or("debug")).init(); | ||
|
||
// Create toplevel | ||
Toplevel::new() | ||
.start("Subsys1", subsys1) | ||
.catch_signals() | ||
.handle_shutdown_requests(Duration::from_millis(1000)) | ||
.await | ||
} |