Skip to content

Commit

Permalink
Rewrite the timeouts
Browse files Browse the repository at this point in the history
Change the strategy of how timeouts work, from a simple timer, to
something a bit more nuanced
  • Loading branch information
anaisbetts committed May 15, 2024
1 parent 326e9fe commit e9cd5d3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions crates/gitbutler-watcher/src/file_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,20 @@ use notify::{RecommendedWatcher, Watcher};
use tokio::task;
use tracing::Level;

/// The timeout for debouncing file change events.
/// This is used to prevent multiple events from being sent for a single file change.
/// We will collect notifications for up to this amount of time at a very
/// maximum before releasing them. This duration will be hit if e.g. a build
/// is constantly running and producing a lot of file changes, we will process
/// them even if the build is still running.
const DEBOUNCE_TIMEOUT: Duration = Duration::from_secs(60);

// The internal rate at which the debouncer will update its state.
const TICK_RATE: Duration = Duration::from_millis(250);
const FLUSH_AFTER_EMPTY: u32 = 3;

// The number of TICK_RATE intervals required of "dead air" (i.e. no new events
// arriving) before we will automatically flush pending events. This means that
// after the disk is quiet for TICK_RATE * FLUSH_AFTER_EMPTY, we will process
// the pending events, even if DEBOUNCE_TIMEOUT hasn't expired yet
const FLUSH_AFTER_EMPTY: u32 = 6;

/// This error is required only because `anyhow::Error` isn't implementing `std::error::Error`, and [`spawn()`]
/// needs to wrap it into a `backoff::Error` which also has to implement the `Error` trait.
Expand Down

0 comments on commit e9cd5d3

Please sign in to comment.