From 7f3a6c81302fe48675b7c85c47a3f43462e1b87a Mon Sep 17 00:00:00 2001 From: Boris Zhou Date: Sat, 19 Mar 2016 18:28:34 +0100 Subject: [PATCH] Fix watch event cooldown --- src/bin/mdbook.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bin/mdbook.rs b/src/bin/mdbook.rs index c8ff6d8a..7f80757a 100644 --- a/src/bin/mdbook.rs +++ b/src/bin/mdbook.rs @@ -170,7 +170,7 @@ fn watch(args: &ArgMatches) -> Result<(), Box> { // do nothing if book.json is not found } - let previous_time = time::get_time().sec; + let mut previous_time = time::get_time(); crossbeam::scope(|scope| { loop { @@ -178,8 +178,11 @@ fn watch(args: &ArgMatches) -> Result<(), Box> { Ok(event) => { // Skip the event if an event has already been issued in the last second - if time::get_time().sec - previous_time < 1 { + let time = time::get_time(); + if time - previous_time < time::Duration::seconds(1) { continue; + } else { + previous_time = time; } if let Some(path) = event.path {