diff --git a/cli/lsp/cache.rs b/cli/lsp/cache.rs index 39b9dca601..1ea3172402 100644 --- a/cli/lsp/cache.rs +++ b/cli/lsp/cache.rs @@ -5,12 +5,12 @@ use crate::cache::FetchCacher; use crate::flags::Flags; use crate::proc_state::ProcState; use crate::resolver::ImportMapResolver; -use crate::tokio_util::create_basic_runtime; use deno_core::error::anyhow; use deno_core::error::AnyError; use deno_core::ModuleSpecifier; use deno_runtime::permissions::Permissions; +use deno_runtime::tokio_util::create_basic_runtime; use import_map::ImportMap; use std::path::PathBuf; use std::thread; diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs index ff3d73f0ff..af2caf22aa 100644 --- a/cli/lsp/config.rs +++ b/cli/lsp/config.rs @@ -1,7 +1,5 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -use crate::tokio_util::create_basic_runtime; - use deno_core::error::anyhow; use deno_core::error::AnyError; use deno_core::parking_lot::RwLock; @@ -11,6 +9,7 @@ use deno_core::serde_json; use deno_core::serde_json::Value; use deno_core::url::Url; use deno_core::ModuleSpecifier; +use deno_runtime::tokio_util::create_basic_runtime; use log::error; use lsp::WorkspaceFolder; use lspower::lsp; diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs index 698fcd7441..fdbf8b27bc 100644 --- a/cli/lsp/diagnostics.rs +++ b/cli/lsp/diagnostics.rs @@ -7,13 +7,13 @@ use super::language_server; use super::tsc; use crate::diagnostics; -use crate::tokio_util::create_basic_runtime; use deno_core::error::anyhow; use deno_core::error::AnyError; use deno_core::resolve_url; use deno_core::serde_json::json; use deno_core::ModuleSpecifier; +use deno_runtime::tokio_util::create_basic_runtime; use log::error; use lspower::lsp; use std::collections::HashMap; diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index 7e3c721300..d5538eb489 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -16,7 +16,6 @@ use super::text::LineIndex; use super::urls::INVALID_SPECIFIER; use crate::config_file::TsConfig; -use crate::tokio_util::create_basic_runtime; use crate::tsc; use crate::tsc::ResolveArgs; @@ -37,6 +36,7 @@ use deno_core::JsRuntime; use deno_core::ModuleSpecifier; use deno_core::OpFn; use deno_core::RuntimeOptions; +use deno_runtime::tokio_util::create_basic_runtime; use log::warn; use lspower::lsp; use regex::Captures; diff --git a/cli/main.rs b/cli/main.rs index d1ee4a0127..7bf23556cf 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -30,7 +30,6 @@ mod resolver; mod source_maps; mod standalone; mod text_encoding; -mod tokio_util; mod tools; mod tsc; mod unix_util; @@ -78,6 +77,7 @@ use deno_core::ModuleSpecifier; use deno_runtime::colors; use deno_runtime::ops::worker_host::CreateWebWorkerCb; use deno_runtime::permissions::Permissions; +use deno_runtime::tokio_util::run_basic; use deno_runtime::web_worker::WebWorker; use deno_runtime::web_worker::WebWorkerOptions; use deno_runtime::worker::MainWorker; @@ -1389,7 +1389,7 @@ pub fn main() { let args: Vec = env::args().collect(); let standalone_res = match standalone::extract_standalone(args.clone()) { Ok(Some((metadata, bundle))) => { - tokio_util::run_basic(standalone::run(bundle, metadata)) + run_basic(standalone::run(bundle, metadata)) } Ok(None) => Ok(()), Err(err) => Err(err), @@ -1417,5 +1417,5 @@ pub fn main() { logger::init(flags.log_level); - unwrap_or_exit(tokio_util::run_basic(get_subcommand(flags))); + unwrap_or_exit(run_basic(get_subcommand(flags))); } diff --git a/cli/tokio_util.rs b/cli/tokio_util.rs deleted file mode 100644 index 695b948025..0000000000 --- a/cli/tokio_util.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. - -pub fn create_basic_runtime() -> tokio::runtime::Runtime { - tokio::runtime::Builder::new_current_thread() - .enable_io() - .enable_time() - // This limits the number of threads for blocking operations (like for - // synchronous fs ops) or CPU bound tasks like when we run dprint in - // parallel for deno fmt. - // The default value is 512, which is an unhelpfully large thread pool. We - // don't ever want to have more than a couple dozen threads. - .max_blocking_threads(32) - .build() - .unwrap() -} - -// TODO(ry) rename to run_local ? -pub fn run_basic(future: F) -> R -where - F: std::future::Future, -{ - let rt = create_basic_runtime(); - let local = tokio::task::LocalSet::new(); - local.block_on(&rt, future) -} diff --git a/cli/tools/test.rs b/cli/tools/test.rs index 820509f69a..d883f18a34 100644 --- a/cli/tools/test.rs +++ b/cli/tools/test.rs @@ -18,7 +18,6 @@ use crate::lockfile; use crate::ops; use crate::proc_state::ProcState; use crate::resolver::ImportMapResolver; -use crate::tokio_util; use crate::tools::coverage::CoverageCollector; use deno_ast::swc::common::comments::CommentKind; @@ -33,6 +32,7 @@ use deno_core::serde_json::json; use deno_core::JsRuntime; use deno_core::ModuleSpecifier; use deno_runtime::permissions::Permissions; +use deno_runtime::tokio_util::run_basic; use log::Level; use rand::rngs::SmallRng; use rand::seq::SliceRandom; @@ -782,7 +782,7 @@ async fn test_specifiers( sender, ); - tokio_util::run_basic(future) + run_basic(future) }); join_handle.join().unwrap() diff --git a/runtime/tokio_util.rs b/runtime/tokio_util.rs index 7a6f4d49e6..695b948025 100644 --- a/runtime/tokio_util.rs +++ b/runtime/tokio_util.rs @@ -13,3 +13,13 @@ pub fn create_basic_runtime() -> tokio::runtime::Runtime { .build() .unwrap() } + +// TODO(ry) rename to run_local ? +pub fn run_basic(future: F) -> R +where + F: std::future::Future, +{ + let rt = create_basic_runtime(); + let local = tokio::task::LocalSet::new(); + local.block_on(&rt, future) +} diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index c70d20ffcf..c7358bc74e 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -4,7 +4,7 @@ use crate::inspector_server::InspectorServer; use crate::js; use crate::ops; use crate::permissions::Permissions; -use crate::tokio_util::create_basic_runtime; +use crate::tokio_util::run_basic; use crate::BootstrapOptions; use deno_broadcast_channel::InMemoryBroadcastChannel; use deno_core::error::AnyError; @@ -545,8 +545,6 @@ pub fn run_web_worker( ) -> Result<(), AnyError> { let name = worker.name.to_string(); - let rt = create_basic_runtime(); - // TODO(bartlomieju): run following block using "select!" // with terminate @@ -587,6 +585,5 @@ pub fn run_web_worker( debug!("Worker thread shuts down {}", &name); result }; - - rt.block_on(fut) + run_basic(fut) }