From d032a1a4e8c52f4ea38d9ca24070203a35436158 Mon Sep 17 00:00:00 2001 From: Bernardo Date: Sun, 6 Jan 2019 18:36:22 +0100 Subject: complete test --- crates/ra_vfs/src/lib.rs | 2 +- crates/ra_vfs/src/watcher.rs | 37 ++++++++++++++++--------------------- 2 files changed, 17 insertions(+), 22 deletions(-) (limited to 'crates/ra_vfs/src') diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs index 5336822b3..1ca94dcd6 100644 --- a/crates/ra_vfs/src/lib.rs +++ b/crates/ra_vfs/src/lib.rs @@ -98,7 +98,7 @@ impl Vfs { pub fn new(mut roots: Vec) -> (Vfs, Vec) { let (worker, worker_handle) = io::start(); - let watcher = Watcher::new().unwrap(); // TODO return Result? + let watcher = Watcher::start().unwrap(); // TODO return Result? let mut res = Vfs { roots: Arena::default(), diff --git a/crates/ra_vfs/src/watcher.rs b/crates/ra_vfs/src/watcher.rs index cc05f949e..1aac23616 100644 --- a/crates/ra_vfs/src/watcher.rs +++ b/crates/ra_vfs/src/watcher.rs @@ -39,7 +39,6 @@ impl WatcherChange { DebouncedEvent::Remove(path) => Some(WatcherChange::Remove(path)), DebouncedEvent::Rename(src, dst) => Some(WatcherChange::Rename(src, dst)), DebouncedEvent::Error(err, path) => { - // TODO log::warn!("watch error {}, {:?}", err, path); None } @@ -48,23 +47,17 @@ impl WatcherChange { } impl Watcher { - pub fn new() -> Result> { + pub fn start() -> Result> { let (input_sender, input_receiver) = mpsc::channel(); let watcher = notify::watcher(input_sender, Duration::from_millis(250))?; let (output_sender, output_receiver) = crossbeam_channel::unbounded(); - let thread = thread::spawn(move || loop { - match input_receiver.recv() { - Ok(ev) => { - // forward relevant events only - if let Some(change) = WatcherChange::from_debounced_event(ev) { - output_sender.send(change).unwrap(); - } - } - Err(err) => { - log::debug!("Watcher stopped ({})", err); - break; - } - } + let thread = thread::spawn(move || { + input_receiver + .into_iter() + // forward relevant events only + .filter_map(WatcherChange::from_debounced_event) + .try_for_each(|change| output_sender.send(change)) + .unwrap() }); Ok(Watcher { receiver: output_receiver, @@ -86,11 +79,13 @@ impl Watcher { pub fn shutdown(mut self) -> thread::Result<()> { self.bomb.defuse(); drop(self.watcher); - let res = self.thread.join(); - match &res { - Ok(()) => log::info!("... Watcher terminated with ok"), - Err(_) => log::error!("... Watcher terminated with err"), - } - res + // TODO this doesn't terminate for some reason + // let res = self.thread.join(); + // match &res { + // Ok(()) => log::info!("... Watcher terminated with ok"), + // Err(_) => log::error!("... Watcher terminated with err"), + // } + // res + Ok(()) } } -- cgit v1.2.3