Watch debounce configuration

It’d be nice to add the ability for the user to configure a difference debounce value for the files watcher.

1 second seems quite excessive to me sometimes, when I could just edit my blog post and see it some handful of milliseconds afterwards on my second monitor.

1 Like

Something like this:

diff --git a/src/cli.rs b/src/cli.rs
index 4c6708f0..bddfe3b4 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -101,6 +101,10 @@ pub enum Command {
         /// Extra path to watch for changes, relative to the project root.
         #[clap(long)]
         extra_watch_path: Vec<String>,
+
+        /// Seconds to debounce file watcher events (allows fractional)
+        #[clap(long, default_value_t = 1.0)]
+        watch_delay: f64,
     },
 
     /// Try to build the project without rendering it. Checks links
diff --git a/src/cmd/serve.rs b/src/cmd/serve.rs
index 8dbb1e4c..2171a43e 100644
--- a/src/cmd/serve.rs
+++ b/src/cmd/serve.rs
@@ -429,6 +429,7 @@ pub fn serve(
     no_port_append: bool,
     utc_offset: UtcOffset,
     extra_watch_paths: Vec<String>,
+    watch_delay: f64,
 ) -> Result<()> {
     let start = Instant::now();
     let (mut site, bind_address, constructed_base_url) = create_new_site(
@@ -481,7 +482,7 @@ pub fn serve(
 
     // Setup watchers
     let (tx, rx) = channel();
-    let mut debouncer = new_debouncer(Duration::from_secs(1), /*tick_rate=*/ None, tx).unwrap();
+    let mut debouncer = new_debouncer(Duration::from_secs_f64(watch_delay), /*tick_rate=*/ None, tx).unwrap();
 
     // We watch for changes on the filesystem for every entry in watch_this
     // Will fail if either:
diff --git a/src/main.rs b/src/main.rs
index cf5fe7bf..d9716dc6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -89,6 +89,7 @@ fn main() {
             fast,
             no_port_append,
             extra_watch_path,
+            watch_delay,
         } => {
             if port != 1111 && !port_is_available(interface, port) {
                 console::error("The requested port is not available");
@@ -119,6 +120,7 @@ fn main() {
                 no_port_append,
                 UtcOffset::current_local_offset().unwrap_or(UtcOffset::UTC),
                 extra_watch_path,
+                watch_delay,
             ) {
                 messages::unravel_errors("Failed to serve the site", &e);
                 std::process::exit(1);

notify_debouncer_full`s behaviour is not what I expect though.

Hey, thanks @yashi. Yes, I arrived to pretty much exactly what you suggested.
I actually already submitted a PR ‘cause I was too much in a hurry to take a look at the code:

2 Likes

Merged (to next) earlier this week!

I’ve no idea how to mark the discussion as “resolved”, though…

2 Likes