Create a new file watcher
(config: WatcherConfig)
| 83 | impl FileWatcher { |
| 84 | /// Create a new file watcher |
| 85 | pub fn new(config: WatcherConfig) -> Result<Self, WatcherError> { |
| 86 | let (event_tx, _) = broadcast::channel(1024); |
| 87 | |
| 88 | let ignore_patterns = config |
| 89 | .ignore_patterns |
| 90 | .iter() |
| 91 | .filter_map(|p| glob::Pattern::new(p).ok()) |
| 92 | .collect(); |
| 93 | |
| 94 | Ok(Self { |
| 95 | watcher: RwLock::new(None), |
| 96 | watched_paths: DashSet::new(), |
| 97 | ignore_patterns, |
| 98 | event_tx, |
| 99 | debounce_ms: config.debounce_ms, |
| 100 | }) |
| 101 | } |
| 102 | |
| 103 | /// Subscribe to file watcher events |
| 104 | pub fn subscribe(&self) -> broadcast::Receiver<WatcherEvent> { |