Expand print_out example into watchexec test case
This commit is contained in:
parent
74d8e73817
commit
5314d201a4
|
@ -1,8 +1,9 @@
|
|||
use std::time::Duration;
|
||||
use std::convert::Infallible;
|
||||
|
||||
use tokio::time::sleep;
|
||||
use watchexec::{
|
||||
action::{Action, Outcome},
|
||||
config::{InitConfigBuilder, RuntimeConfig},
|
||||
signal::Signal,
|
||||
Watchexec,
|
||||
};
|
||||
|
||||
|
@ -18,12 +19,27 @@ async fn main() -> color_eyre::eyre::Result<()> {
|
|||
Ok::<(), std::convert::Infallible>(())
|
||||
});
|
||||
|
||||
let runtime = RuntimeConfig::default();
|
||||
let mut runtime = RuntimeConfig::default();
|
||||
runtime.command(["date"]);
|
||||
runtime.on_action(|action: Action| async move {
|
||||
eprintln!("Watchexec Action: {:?}", action);
|
||||
|
||||
if action
|
||||
.events
|
||||
.iter()
|
||||
.flat_map(|event| event.signals())
|
||||
.any(|sig| sig == Signal::Interrupt)
|
||||
{
|
||||
action.outcome(Outcome::Exit);
|
||||
} else {
|
||||
action.outcome(Outcome::both(Outcome::Stop, Outcome::Start));
|
||||
}
|
||||
|
||||
Ok::<(), Infallible>(())
|
||||
});
|
||||
|
||||
let wx = Watchexec::new(init.build()?, runtime)?;
|
||||
wx.main();
|
||||
|
||||
sleep(Duration::from_secs(1)).await;
|
||||
wx.main().await??;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -77,10 +77,16 @@ impl Watchexec {
|
|||
|
||||
let error_hook = subtask!(error_hook, error_hook(er_r, eh));
|
||||
|
||||
try_join!(action, error_hook, fs, signal).map(drop).or_else(|e| if matches!(e, CriticalError::Exit) {
|
||||
trace!("got graceful exit request via critical error, erasing the error");
|
||||
Ok(())
|
||||
} else { Err(e) })
|
||||
try_join!(action, error_hook, fs, signal)
|
||||
.map(drop)
|
||||
.or_else(|e| {
|
||||
if matches!(e, CriticalError::Exit) {
|
||||
trace!("got graceful exit request via critical error, erasing the error");
|
||||
Ok(())
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
trace!("done with setup");
|
||||
|
|
Loading…
Reference in New Issue