From 724e39f13f2f144703ce00e156cacfc653d8e209 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Fri, 7 Feb 2020 17:54:44 -0500 Subject: [PATCH] Enable thread pool for blocking ops (#3912) --- cli/ops/dispatch_json.rs | 10 +--------- cli/tokio_util.rs | 5 +++-- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/cli/ops/dispatch_json.rs b/cli/ops/dispatch_json.rs index 0806001abd..60c57ef671 100644 --- a/cli/ops/dispatch_json.rs +++ b/cli/ops/dispatch_json.rs @@ -103,15 +103,7 @@ where if is_sync { Ok(JsonOp::Sync(f()?)) } else { - // TODO(ry) use thread pool. - let fut = crate::tokio_util::spawn_thread(f); - /* - let fut = async move { - tokio::task::spawn_blocking(move || f()) - .await - .map_err(ErrBox::from)? - }.boxed_local(); - */ + let fut = async move { tokio::task::spawn_blocking(f).await.unwrap() }; Ok(JsonOp::Async(fut.boxed_local())) } } diff --git a/cli/tokio_util.rs b/cli/tokio_util.rs index 6ffc57b1a6..e5878cdf7b 100644 --- a/cli/tokio_util.rs +++ b/cli/tokio_util.rs @@ -1,5 +1,4 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -use futures::Future; // TODO(ry) rename to run_local ? pub fn run_basic(future: F) -> R @@ -15,7 +14,9 @@ where rt.block_on(future) } -pub fn spawn_thread(f: F) -> impl Future +// TODO(ry) maybe replace with tokio::task::spawn_blocking +#[cfg(test)] +pub fn spawn_thread(f: F) -> impl std::future::Future where F: 'static + Send + FnOnce() -> R, R: 'static + Send,