From 0cd605515c99458fa80cd4a1a3906f3db37a86ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 21 Jan 2020 14:26:11 +0100 Subject: refactor: don't create new runtime for fs ops (#3730) --- cli/ops/dispatch_json.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'cli/ops') diff --git a/cli/ops/dispatch_json.rs b/cli/ops/dispatch_json.rs index 7f53a3d80..de1f0a752 100644 --- a/cli/ops/dispatch_json.rs +++ b/cli/ops/dispatch_json.rs @@ -1,12 +1,12 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use deno_core::*; use futures::future::FutureExt; -use futures::task::SpawnExt; pub use serde_derive::Deserialize; use serde_json::json; pub use serde_json::Value; use std::future::Future; use std::pin::Pin; +use tokio::task; pub type AsyncJsonOp = Pin> + Send>>; @@ -96,11 +96,12 @@ where if is_sync { Ok(JsonOp::Sync(f()?)) } else { - //TODO(afinch7) replace this with something more efficent. - let pool = futures::executor::ThreadPool::new().unwrap(); - let handle = pool - .spawn_with_handle(futures::future::lazy(move |_cx| f())) - .unwrap(); - Ok(JsonOp::Async(handle.boxed())) + let fut = async move { + task::spawn_blocking(move || f()) + .await + .map_err(ErrBox::from)? + } + .boxed(); + Ok(JsonOp::Async(fut.boxed())) } } -- cgit v1.2.3