2023-01-02 21:00:42 +00:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2020-12-13 18:45:53 +00:00
|
|
|
|
|
|
|
pub fn create_basic_runtime() -> tokio::runtime::Runtime {
|
2021-01-12 07:50:02 +00:00
|
|
|
tokio::runtime::Builder::new_current_thread()
|
2020-12-13 18:45:53 +00:00
|
|
|
.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.
|
2021-01-12 07:50:02 +00:00
|
|
|
.max_blocking_threads(32)
|
2020-12-13 18:45:53 +00:00
|
|
|
.build()
|
|
|
|
.unwrap()
|
|
|
|
}
|
2021-10-21 11:05:43 +00:00
|
|
|
|
2022-07-11 17:02:23 +00:00
|
|
|
pub fn run_local<F, R>(future: F) -> R
|
2021-10-21 11:05:43 +00:00
|
|
|
where
|
|
|
|
F: std::future::Future<Output = R>,
|
|
|
|
{
|
|
|
|
let rt = create_basic_runtime();
|
|
|
|
let local = tokio::task::LocalSet::new();
|
|
|
|
local.block_on(&rt, future)
|
|
|
|
}
|