From 80be61ed78e8410e013cb94879435d54a4907c30 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 2 Sep 2018 14:46:15 +0300 Subject: project model --- crates/server/src/vfs.rs | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) (limited to 'crates/server/src/vfs.rs') diff --git a/crates/server/src/vfs.rs b/crates/server/src/vfs.rs index 2e4319cdb..2acc3f55f 100644 --- a/crates/server/src/vfs.rs +++ b/crates/server/src/vfs.rs @@ -1,14 +1,14 @@ use std::{ path::PathBuf, - thread, fs, }; use crossbeam_channel::{Sender, Receiver, bounded}; -use drop_bomb::DropBomb; use walkdir::WalkDir; -use Result; +use { + thread_watcher::ThreadWatcher, +}; #[derive(Debug)] @@ -24,26 +24,10 @@ pub enum FileEventKind { Remove, } -pub struct Watcher { - thread: thread::JoinHandle<()>, - bomb: DropBomb, -} - -impl Watcher { - pub fn stop(mut self) -> Result<()> { - self.bomb.defuse(); - self.thread.join() - .map_err(|_| format_err!("file watcher died")) - } -} - -pub fn watch(roots: Vec) -> (Receiver>, Watcher) { +pub fn watch(roots: Vec) -> (Receiver>, ThreadWatcher) { let (sender, receiver) = bounded(16); - let thread = thread::spawn(move || run(roots, sender)); - (receiver, Watcher { - thread, - bomb: DropBomb::new("Watcher should be stopped explicitly"), - }) + let watcher = ThreadWatcher::spawn("vfs", move || run(roots, sender)); + (receiver, watcher) } fn run(roots: Vec, sender: Sender>) { -- cgit v1.2.3