From 41ed4cd34e70683e4b2b81e11b41082e7f73f47f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 7 Oct 2019 10:31:56 +0200 Subject: [PATCH] use single thread runime in tokio_util::block_on (#3080) --- cli/tokio_util.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cli/tokio_util.rs b/cli/tokio_util.rs index 8314197597..678bb8e667 100644 --- a/cli/tokio_util.rs +++ b/cli/tokio_util.rs @@ -36,8 +36,10 @@ where /// THIS IS A HACK AND SHOULD BE AVOIDED. /// -/// This creates a new tokio runtime, with many new threads, to execute the -/// given future. This is useful when we want to block the main runtime to +/// This spawns a new thread and creates a single-threaded tokio runtime on that thread, +/// to execute the given future. +/// +/// This is useful when we want to block the main runtime to /// resolve a future without worrying that we'll use up all the threads in the /// main runtime. pub fn block_on(future: F) -> Result @@ -50,10 +52,7 @@ where let (sender, receiver) = channel(); // Create a new runtime to evaluate the future asynchronously. thread::spawn(move || { - let r = match create_threadpool_runtime() { - Ok(mut rt) => rt.block_on(future), - Err(e) => Err(ErrBox::from(e)), - }; + let r = tokio::runtime::current_thread::block_on_all(future); sender .send(r) .expect("Unable to send blocking future result")