mirror of
https://github.com/denoland/deno.git
synced 2024-11-26 16:09:27 -05:00
10e4b2e140
Yearly tradition of creating extra noise in git.
24 lines
797 B
Rust
24 lines
797 B
Rust
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
|
|
pub fn create_basic_runtime() -> tokio::runtime::Runtime {
|
|
tokio::runtime::Builder::new_current_thread()
|
|
.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.
|
|
.max_blocking_threads(32)
|
|
.build()
|
|
.unwrap()
|
|
}
|
|
|
|
pub fn run_local<F, R>(future: F) -> R
|
|
where
|
|
F: std::future::Future<Output = R>,
|
|
{
|
|
let rt = create_basic_runtime();
|
|
let local = tokio::task::LocalSet::new();
|
|
local.block_on(&rt, future)
|
|
}
|