2021-01-11 12:13:41 -05:00
|
|
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
2019-04-23 16:27:44 -04:00
|
|
|
|
2020-02-11 04:04:59 -05:00
|
|
|
pub fn create_basic_runtime() -> tokio::runtime::Runtime {
|
2021-01-12 02:50:02 -05:00
|
|
|
tokio::runtime::Builder::new_current_thread()
|
2020-02-03 18:08:44 -05:00
|
|
|
.enable_io()
|
|
|
|
.enable_time()
|
2020-08-31 17:38:25 -04:00
|
|
|
// 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 02:50:02 -05:00
|
|
|
.max_blocking_threads(32)
|
2019-12-30 08:57:17 -05:00
|
|
|
.build()
|
2020-02-11 04:04:59 -05:00
|
|
|
.unwrap()
|
2020-02-03 18:08:44 -05:00
|
|
|
}
|
|
|
|
|
2020-02-11 04:04:59 -05:00
|
|
|
// TODO(ry) rename to run_local ?
|
|
|
|
pub fn run_basic<F, R>(future: F) -> R
|
2020-02-03 18:08:44 -05:00
|
|
|
where
|
2020-08-18 12:30:13 -04:00
|
|
|
F: std::future::Future<Output = R>,
|
2020-02-03 18:08:44 -05:00
|
|
|
{
|
2021-01-12 02:50:02 -05:00
|
|
|
let rt = create_basic_runtime();
|
2021-04-08 18:34:15 -04:00
|
|
|
let local = tokio::task::LocalSet::new();
|
|
|
|
local.block_on(&rt, future)
|
2019-04-14 16:07:24 -04:00
|
|
|
}
|