mirror of
https://github.com/denoland/deno.git
synced 2024-11-29 16:30:56 -05:00
c6bb3d5a10
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
30 lines
848 B
Rust
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());
|
|
}
|