1158: cleanup cancellation r=matklad a=matklad

Now that we explicitelly exit the reading loop on exit notification,
we can assume that the sender is always alive

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2019-04-17 08:56:36 +00:00
commit 645a7b77b6
2 changed files with 6 additions and 13 deletions

View file

@ -27,9 +27,7 @@ pub fn stdio_transport() -> (Receiver<RawMessage>, Sender<RawMessage>, Threads)
_ => false,
};
if let Err(_) = reader_sender.send(msg) {
break;
}
reader_sender.send(msg).unwrap();
if is_exit {
break;

View file

@ -77,7 +77,7 @@ pub struct Server {
req_id: Cell<u64>,
messages: RefCell<Vec<RawMessage>>,
dir: TempDir,
worker: Option<Worker<RawMessage, RawMessage>>,
worker: Worker<RawMessage, RawMessage>,
}
impl Server {
@ -99,12 +99,7 @@ impl Server {
.unwrap()
},
);
let res = Server {
req_id: Cell::new(1),
dir,
messages: Default::default(),
worker: Some(worker),
};
let res = Server { req_id: Cell::new(1), dir, messages: Default::default(), worker };
for (path, text) in files {
res.send_notification(RawNotification::new::<DidOpenTextDocument>(
@ -157,7 +152,7 @@ impl Server {
}
fn send_request_(&self, r: RawRequest) -> Value {
let id = r.id;
self.worker.as_ref().unwrap().sender().send(RawMessage::Request(r)).unwrap();
self.worker.sender().send(RawMessage::Request(r)).unwrap();
while let Some(msg) = self.recv() {
match msg {
RawMessage::Request(req) => panic!("unexpected request: {:?}", req),
@ -197,13 +192,13 @@ impl Server {
}
}
fn recv(&self) -> Option<RawMessage> {
recv_timeout(&self.worker.as_ref().unwrap().receiver()).map(|msg| {
recv_timeout(&self.worker.receiver()).map(|msg| {
self.messages.borrow_mut().push(msg.clone());
msg
})
}
fn send_notification(&self, not: RawNotification) {
self.worker.as_ref().unwrap().sender().send(RawMessage::Notification(not)).unwrap();
self.worker.sender().send(RawMessage::Notification(not)).unwrap();
}
pub fn path(&self) -> &Path {