From b42336cb74c87126b3c43dc0a19e18a1896b5edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Mon, 23 Aug 2021 03:11:58 +1200 Subject: [PATCH] Actually watch files in example --- lib/examples/print_out.rs | 6 +++++- lib/src/command.rs | 1 + lib/src/watchexec.rs | 7 ++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/examples/print_out.rs b/lib/examples/print_out.rs index d803c95..a86d8bf 100644 --- a/lib/examples/print_out.rs +++ b/lib/examples/print_out.rs @@ -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>(()) diff --git a/lib/src/command.rs b/lib/src/command.rs index 3561d0d..e7f5673 100644 --- a/lib/src/command.rs +++ b/lib/src/command.rs @@ -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 => { diff --git a/lib/src/watchexec.rs b/lib/src/watchexec.rs index c153ea9..2a35164 100644 --- a/lib/src/watchexec.rs +++ b/lib/src/watchexec.rs @@ -48,8 +48,13 @@ impl Watchexec { ) -> Result, 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());