on master help sign in
fix erroneous write sender close

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

commit7b11e9ac6941188c6f6148961fdd97e34988490e authorSkyler Hawthorne <skyler@dead10ck.com> dateTue 23 Aug 2022, 17:21 (4 years ago) parentd544376
1 file changed+11−1
helix-view/src/document.rs+11−1
helix-view/src/document.rs+11−1
@@ -13,6 +13,7 @@ use std::future::Future;
1313use std::path::{Path, PathBuf};
1414use std::str::FromStr;
1515use std::sync::Arc;
16+use tokio::sync::mpsc::error::TryRecvError;
1617use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
1718
1819use tokio::sync::Mutex;
@@ -662,7 +663,16 @@ impl Document {
662663 let save_req = if block {
663664 rx.recv().await
664665 } else {
665− rx.try_recv().ok()
666+ let msg = rx.try_recv();
667+
668+ if let Err(err) = msg {
669+ match err {
670+ TryRecvError::Empty => return None,
671+ TryRecvError::Disconnected => None,
672+ }
673+ } else {
674+ msg.ok()
675+ }
666676 };
667677
668678 let save = match save_req {