Skip to content

Commit

Permalink
refactor(core): try run task in spawn thread
Browse files Browse the repository at this point in the history
  • Loading branch information
hardfist committed Sep 22, 2024
1 parent e58ac85 commit 2fbda57
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/rspack_core/src/utils/task_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use rspack_util::ext::AsAny;
use tokio::{
runtime::Handle,
sync::mpsc::{self, error::TryRecvError},
task::spawn_blocking,
};

/// Result returned by task
Expand Down Expand Up @@ -86,7 +87,11 @@ pub fn run_task_loop_with_event<Ctx: 'static>(
let is_expected_shutdown = is_expected_shutdown.clone();
active_task_count += 1;
tokio::spawn(async move {
let r = task.async_run().await;
let r =
spawn_blocking(|| Handle::current().block_on(async move { task.async_run().await }))
.await
.expect("spawn task failed");

if !is_expected_shutdown.load(Ordering::Relaxed) {
tx.send(r).expect("failed to send error message");
}
Expand Down

0 comments on commit 2fbda57

Please sign in to comment.