From f1b1a3f389827af8983a78680c066fdad337ae32 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Thu, 21 Oct 2021 13:05:43 +0200 Subject: refactor: move `mod tokio_util` to runtime (#12332) This avoids a bunch of duplicated code. --- runtime/tokio_util.rs | 10 ++++++++++ runtime/web_worker.rs | 7 ++----- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'runtime') diff --git a/runtime/tokio_util.rs b/runtime/tokio_util.rs index 7a6f4d49e..695b94802 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 c70d20ffc..c7358bc74 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) } -- cgit v1.2.3