From ce60be2ec96c88420c9f5e4c21a6f9742d42afb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sun, 22 Aug 2021 02:53:31 +1200 Subject: [PATCH] Add print_out example --- lib/examples/print_out.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 lib/examples/print_out.rs diff --git a/lib/examples/print_out.rs b/lib/examples/print_out.rs new file mode 100644 index 00000000..ad8d8589 --- /dev/null +++ b/lib/examples/print_out.rs @@ -0,0 +1,30 @@ +use std::time::Duration; + +use tokio::time::sleep; +use watchexec::{ + config::{InitConfigBuilder, RuntimeConfigBuilder}, + Watchexec, +}; + +// Run with: `env RUST_LOG=debug cargo run --example print_out` +#[tokio::main] +async fn main() -> color_eyre::eyre::Result<()> { + tracing_subscriber::fmt::init(); + color_eyre::install()?; + + let init = InitConfigBuilder::default() + .error_handler(Box::new(|err| async move { + eprintln!("Watchexec Runtime Error: {}", err); + Ok::<(), std::convert::Infallible>(()) + })) + .build()?; + + let runtime = RuntimeConfigBuilder::default().build()?; + + let wx = Watchexec::new(init, runtime)?; + wx.main(); + + sleep(Duration::from_secs(1)).await; + + Ok(()) +}