Actually watch files in example

This commit is contained in:
Félix Saparelli 2021-08-23 03:11:58 +12:00
parent b2effda341
commit b42336cb74
No known key found for this signature in database
GPG Key ID: B948C4BAE44FC474
3 changed files with 12 additions and 2 deletions

View File

@ -20,6 +20,7 @@ async fn main() -> color_eyre::eyre::Result<()> {
});
let mut runtime = RuntimeConfig::default();
runtime.pathset(["src"]);
runtime.command(["date"]);
runtime.on_action(|action: Action| async move {
eprintln!("Watchexec Action: {:?}", action);
@ -32,7 +33,10 @@ async fn main() -> color_eyre::eyre::Result<()> {
{
action.outcome(Outcome::Exit);
} else {
action.outcome(Outcome::both(Outcome::Stop, Outcome::Start));
action.outcome(Outcome::if_running(
Outcome::both(Outcome::Stop, Outcome::Start),
Outcome::Start,
));
}
Ok::<(), Infallible>(())

View File

@ -71,6 +71,7 @@ impl Shell {
/// - Panics if the string in the `Unix` variant is empty or only whitespace.
pub fn to_command(&self, cmd: &[String]) -> Command {
assert!(!cmd.is_empty(), "cmd was empty");
trace!(shell=?self, ?cmd, "constructing command");
match self {
Shell::None => {

View File

@ -48,8 +48,13 @@ impl Watchexec {
) -> Result<Arc<Self>, CriticalError> {
debug!(?init, ?runtime, pid=%std::process::id(), "initialising");
let (fs_s, fs_r) = watch::channel(take(&mut runtime.fs));
let (ac_s, ac_r) = watch::channel(take(&mut runtime.action));
let (fs_s, fs_r) = watch::channel(fs::WorkingData::default());
// TODO: figure out how to do this (aka start the fs work) after the main task start lock
trace!("sending initial config to fs worker");
fs_s.send(take(&mut runtime.fs))
.expect("cannot send to just-created fs watch (bug)");
trace!("creating main task");
let notify = Arc::new(Notify::new());