use notify::{Config, RecommendedWatcher, Watcher};
use std::sync::mpsc::channel;
use std::time::Duration;
use crate::services::file_watcher::{FileWatcher, WatchConfig};
impl FileWatcher {
pub fn with_config(config: WatchConfig) -> Result<Self, notify::Error> {
let (tx, rx) = channel();
let watcher = RecommendedWatcher::new(
move |res| {
let _ = tx.send(res);
},
Config::default().with_poll_interval(Duration::from_millis(config.debounce_ms)),
)?;
Ok(Self {
watcher,
rx,
config,
changed_paths: Vec::new(),
})
}
}