Fix Drop impl for WasmExtension

Richard Feldman created

Change summary

crates/extension_host/src/wasm_host.rs | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

Detailed changes

crates/extension_host/src/wasm_host.rs 🔗

@@ -68,7 +68,7 @@ pub struct WasmHost {
 
 #[derive(Clone, Debug)]
 pub struct WasmExtension {
-    tx: UnboundedSender<ExtensionCall>,
+    tx: Arc<UnboundedSender<ExtensionCall>>,
     pub manifest: Arc<ExtensionManifest>,
     pub work_dir: Arc<Path>,
     #[allow(unused)]
@@ -76,6 +76,15 @@ pub struct WasmExtension {
     _task: Arc<Task<Result<(), gpui_tokio::JoinError>>>,
 }
 
+impl Drop for WasmExtension {
+    fn drop(&mut self) {
+        // Only close the channel when this is the last clone holding the sender
+        if Arc::strong_count(&self.tx) == 1 {
+            self.tx.close_channel();
+        }
+    }
+}
+
 #[async_trait]
 impl extension::Extension for WasmExtension {
     fn manifest(&self) -> Arc<ExtensionManifest> {
@@ -670,7 +679,7 @@ impl WasmHost {
             Ok(WasmExtension {
                 manifest,
                 work_dir,
-                tx,
+                tx: Arc::new(tx),
                 zed_api_version,
                 _task: task,
             })