From ea93733694024271c79bf7f2ffd2bed1151f1da1 Mon Sep 17 00:00:00 2001 From: NKID00 Date: Thu, 22 Aug 2024 13:27:28 +0800 Subject: [PATCH] fix: drop JoinHandle in worker thread --- core/src/services/monoiofs/core.rs | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/core/src/services/monoiofs/core.rs b/core/src/services/monoiofs/core.rs index d00e7b84717..25acc7e8cea 100644 --- a/core/src/services/monoiofs/core.rs +++ b/core/src/services/monoiofs/core.rs @@ -24,7 +24,6 @@ use flume::Receiver; use flume::Sender; use futures::channel::oneshot; use futures::Future; -use monoio::task::JoinHandle; use monoio::FusionDriver; use monoio::RuntimeBuilder; @@ -122,30 +121,22 @@ impl MonoiofsCore { self.unwrap(rx.await) } - /// Create a TaskSpawner, send it to the thread pool, spawn the task - /// and return its [`JoinHandle`]. Task panic cannot propagate - /// through the [`JoinHandle`] and should be handled elsewhere. - pub async fn spawn(&self, f: F) -> JoinHandle + /// Create a TaskSpawner, send it to the thread pool and spawn the task. + pub async fn spawn(&self, f: F) where F: FnOnce() -> Fut + 'static + Send, Fut: Future, - T: 'static + Send, + T: 'static, { - // oneshot channel to send JoinHandle back - let (tx, rx) = oneshot::channel(); let result = self .tx .send_async(Box::new(move || { // task will be spawned on current thread, task panic // will cause current worker thread panic - let handle = monoio::spawn(async move { f().await }); - // discard the result if send failed due to - // MonoiofsCore::spawn cancelled - let _ = tx.send(handle); + monoio::spawn(async move { f().await }); })) .await; self.unwrap(result); - self.unwrap(rx.await) } /// This method always panics. It is called only when at least a