mirror of
https://github.com/watchexec/watchexec.git
synced 2024-09-30 07:01:34 +02:00
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::{
|
use watchexec::{
|
||||||
|
action::{Action, Outcome},
|
||||||
config::{InitConfigBuilder, RuntimeConfig},
|
config::{InitConfigBuilder, RuntimeConfig},
|
||||||
|
signal::Signal,
|
||||||
Watchexec,
|
Watchexec,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -18,12 +19,27 @@ async fn main() -> color_eyre::eyre::Result<()> {
|
|||||||
Ok::<(), std::convert::Infallible>(())
|
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)?;
|
let wx = Watchexec::new(init.build()?, runtime)?;
|
||||||
wx.main();
|
wx.main().await??;
|
||||||
|
|
||||||
sleep(Duration::from_secs(1)).await;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -77,10 +77,16 @@ impl Watchexec {
|
|||||||
|
|
||||||
let error_hook = subtask!(error_hook, error_hook(er_r, eh));
|
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) {
|
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");
|
trace!("got graceful exit request via critical error, erasing the error");
|
||||||
Ok(())
|
Ok(())
|
||||||
} else { Err(e) })
|
} else {
|
||||||
|
Err(e)
|
||||||
|
}
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
trace!("done with setup");
|
trace!("done with setup");
|
||||||
|
Loading…
Reference in New Issue
Block a user