mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
project model
This commit is contained in:
parent
7fad13de73
commit
80be61ed78
11 changed files with 251 additions and 78 deletions
33
crates/server/src/thread_watcher.rs
Normal file
33
crates/server/src/thread_watcher.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
use std::thread;
|
||||
use drop_bomb::DropBomb;
|
||||
use Result;
|
||||
|
||||
pub struct ThreadWatcher {
|
||||
name: &'static str,
|
||||
thread: thread::JoinHandle<()>,
|
||||
bomb: DropBomb,
|
||||
}
|
||||
|
||||
impl ThreadWatcher {
|
||||
pub fn spawn(name: &'static str, f: impl FnOnce() + Send + 'static) -> ThreadWatcher {
|
||||
let thread = thread::spawn(f);
|
||||
ThreadWatcher {
|
||||
name,
|
||||
thread,
|
||||
bomb: DropBomb::new(format!("ThreadWatcher {} was not stopped", name)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stop(mut self) -> Result<()> {
|
||||
info!("waiting for {} to finish ...", self.name);
|
||||
let name = self.name;
|
||||
self.bomb.defuse();
|
||||
let res = self.thread.join()
|
||||
.map_err(|_| format_err!("ThreadWatcher {} died", name));
|
||||
match &res {
|
||||
Ok(()) => info!("... {} terminated with ok", name),
|
||||
Err(_) => error!("... {} terminated with err", name)
|
||||
}
|
||||
res
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue