diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2020-02-07 17:54:44 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-07 17:54:44 -0500 |
commit | 724e39f13f2f144703ce00e156cacfc653d8e209 (patch) | |
tree | d6ee7f37fef3dfb0326d6c262e358a7f404d98fe | |
parent | 99186dbaa25c5715103f6a0e0df9fae9488470b3 (diff) |
Enable thread pool for blocking ops (#3912)
-rw-r--r-- | cli/ops/dispatch_json.rs | 10 | ||||
-rw-r--r-- | 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 0806001ab..60c57ef67 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 6ffc57b1a..e5878cdf7 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<F, R>(future: F) -> R @@ -15,7 +14,9 @@ where rt.block_on(future) } -pub fn spawn_thread<F, R>(f: F) -> impl Future<Output = R> +// TODO(ry) maybe replace with tokio::task::spawn_blocking +#[cfg(test)] +pub fn spawn_thread<F, R>(f: F) -> impl std::future::Future<Output = R> where F: 'static + Send + FnOnce() -> R, R: 'static + Send, |