From 6b5b793b46a5953275a81bb1d0581e9a019a3743 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Mon, 2 Dec 2024 20:30:36 +0900 Subject: [PATCH] fix(runtime): simplify spawn_blocking --- compio-runtime/src/runtime/mod.rs | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/compio-runtime/src/runtime/mod.rs b/compio-runtime/src/runtime/mod.rs index b164c13e..67dc2052 100644 --- a/compio-runtime/src/runtime/mod.rs +++ b/compio-runtime/src/runtime/mod.rs @@ -2,7 +2,7 @@ use std::{ any::Any, cell::RefCell, collections::VecDeque, - future::{Future, poll_fn, ready}, + future::{Future, ready}, io, marker::PhantomData, panic::AssertUnwindSafe, @@ -220,31 +220,7 @@ impl Runtime { let res = std::panic::catch_unwind(AssertUnwindSafe(f)); BufResult(Ok(0), res) }); - let closure = async move { - let mut op = op; - loop { - match self.submit(op).await { - BufResult(Ok(_), rop) => break rop.into_inner(), - BufResult(Err(_), rop) => op = rop, - } - // Possible error: thread pool is full, or failed to create notify handle. - // Push the future to the back of the queue. - let mut yielded = false; - poll_fn(|cx| { - if yielded { - Poll::Ready(()) - } else { - yielded = true; - cx.waker().wake_by_ref(); - Poll::Pending - } - }) - .await; - } - }; - // SAFETY: the closure catches the shared reference of self, which is in an Rc - // so it won't be moved. - unsafe { self.spawn_unchecked(closure) } + unsafe { self.spawn_unchecked(self.submit(op).map(|res| res.1.into_inner())) } } /// Attach a raw file descriptor/handle/socket to the runtime.