From 680b86b17c63b67f768bc5da5f34e5ccf056a0ce Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 9 Sep 2021 17:57:06 -0700 Subject: [PATCH] Avoid holding strong handle to Channel in long-lived task --- zed/src/channel.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/zed/src/channel.rs b/zed/src/channel.rs index 5c7a2aaa1a..aa182c0540 100644 --- a/zed/src/channel.rs +++ b/zed/src/channel.rs @@ -88,12 +88,12 @@ impl ChannelList { rpc: Arc, cx: &mut ModelContext, ) -> Self { - let _task = cx.spawn(|this, mut cx| { + let _task = cx.spawn_weak(|this, mut cx| { let rpc = rpc.clone(); async move { let mut status = rpc.status(); - loop { - match status.recv().await.unwrap() { + while let Some((status, this)) = status.recv().await.zip(this.upgrade(&cx)) { + match status { rpc::Status::Connected { .. } => { let response = rpc .request(proto::GetChannels {}) @@ -128,6 +128,7 @@ impl ChannelList { _ => {} } } + Ok(()) } .log_err() });