ratatui_toolkit/services/git_watcher/methods/drain_events.rs
1//! Drain pending events without processing.
2
3use std::sync::mpsc::TryRecvError;
4
5use crate::services::git_watcher::GitWatcher;
6
7impl GitWatcher {
8 /// Drain all pending events without processing them.
9 ///
10 /// This clears the event queue and resets the pending changes flag,
11 /// useful when you want to ignore accumulated changes
12 /// (e.g., after a batch operation).
13 ///
14 /// # Example
15 ///
16 /// ```no_run
17 /// use ratatui_toolkit::services::git_watcher::GitWatcher;
18 /// use std::path::Path;
19 ///
20 /// let mut watcher = GitWatcher::new().unwrap();
21 /// watcher.watch(Path::new("/path/to/repo")).unwrap();
22 ///
23 /// // After some operation that causes many changes:
24 /// watcher.drain_events();
25 /// ```
26 pub fn drain_events(&mut self) {
27 loop {
28 match self.rx.try_recv() {
29 Ok(_) => continue,
30 Err(TryRecvError::Empty) => break,
31 Err(TryRecvError::Disconnected) => break,
32 }
33 }
34 self.has_pending_changes = false;
35 }
36}