1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00
denoland-deno/cli/tokio_util.rs
Bartek Iwańczuk c6bb3d5a10 remove tokio_util::block_on (#3388)
This PR removes tokio_util::block_on - refactored compiler and file 
fetcher slightly so that we can safely block there - that's because 
only blocking path consist of only synchronous operations.

Additionally I removed excessive use of tokio_util::panic_on_error 
and tokio_util::run_in_task and moved both functions to cli/worker.rs, 
to tests module.

Closes #2960
2019-11-22 12:46:57 -05:00

30 lines
848 B
Rust

// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use futures;
use futures::future::FutureExt;
use futures::future::TryFutureExt;
use std::future::Future;
use tokio;
use tokio::runtime;
pub fn create_threadpool_runtime(
) -> Result<tokio::runtime::Runtime, tokio::io::Error> {
runtime::Builder::new()
.panic_handler(|err| std::panic::resume_unwind(err))
.build()
}
pub fn run<F>(future: F)
where
F: Future<Output = Result<(), ()>> + Send + 'static,
{
// tokio::runtime::current_thread::run(future)
let rt = create_threadpool_runtime().expect("Unable to create Tokio runtime");
rt.block_on_all(future.boxed().compat()).unwrap();
}
pub fn run_on_current_thread<F>(future: F)
where
F: Future<Output = Result<(), ()>> + Send + 'static,
{
tokio::runtime::current_thread::run(future.boxed().compat());
}