From 843841981c32bb61e95d5670277b4b96b45788e3 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 2 Jun 2024 15:52:53 +0200 Subject: [PATCH] minor refactor --- .../vendor/debouncer/src/lib.rs | 86 +++++++++---------- .../vendor/debouncer/src/tests/mod.rs | 3 +- 2 files changed, 43 insertions(+), 46 deletions(-) diff --git a/crates/gitbutler-watcher/vendor/debouncer/src/lib.rs b/crates/gitbutler-watcher/vendor/debouncer/src/lib.rs index a50033b49..7f67d6603 100644 --- a/crates/gitbutler-watcher/vendor/debouncer/src/lib.rs +++ b/crates/gitbutler-watcher/vendor/debouncer/src/lib.rs @@ -569,58 +569,58 @@ pub fn new_debouncer_opt= threshold { + let mut should_flush = flush.load(Ordering::Acquire); + + std::thread::sleep(tick); + + let send_data; + let errors; + { + let mut lock = data.lock(); + + let queue_count = lock.queues.values().fold(0, |acc, x| acc + x.events.len()); + if prev_queue_count == queue_count { + idle_count += 1; + } else { + prev_queue_count = queue_count + } + + if flush_after.map_or(false, |threshold| idle_count >= threshold) { idle_count = 0; prev_queue_count = 0; should_flush = true; } - } - send_data = lock.debounced_events(should_flush); - if should_flush { - flush_c.store(false, Ordering::Release); - } + send_data = lock.debounced_events(should_flush); + if should_flush { + flush.store(false, Ordering::Release); + } - errors = lock.errors(); - } - if !send_data.is_empty() { - if should_flush { - tracing::debug!("Flushed {} events", send_data.len()); + errors = lock.errors(); } + if !send_data.is_empty() { + if should_flush { + tracing::debug!("Flushed {} events", send_data.len()); + } - event_handler.handle_event(Ok(send_data)); - } - if !errors.is_empty() { - event_handler.handle_event(Err(errors)); + event_handler.handle_event(Ok(send_data)); + } + if !errors.is_empty() { + event_handler.handle_event(Err(errors)); + } } })?; @@ -638,15 +638,13 @@ pub fn new_debouncer_opt