Skip to content

Commit

Permalink
fix erroneous write sender close
Browse files Browse the repository at this point in the history
This was not distinguishing the error types when trying a receive on an empty
receiver, which was erroneously causing the sender to be closed when trying to
flush the writes when there were none
  • Loading branch information
dead10ck committed Oct 19, 2022
1 parent d544376 commit 7b11e9a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::future::Future;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::sync::Arc;
use tokio::sync::mpsc::error::TryRecvError;
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};

use tokio::sync::Mutex;
Expand Down Expand Up @@ -662,7 +663,16 @@ impl Document {
let save_req = if block {
rx.recv().await
} else {
rx.try_recv().ok()
let msg = rx.try_recv();

if let Err(err) = msg {
match err {
TryRecvError::Empty => return None,
TryRecvError::Disconnected => None,
}
} else {
msg.ok()
}
};

let save = match save_req {
Expand Down

0 comments on commit 7b11e9a

Please sign in to comment.