Skip to content

Commit 0b151d6

Browse files
committed
Add env vars to configure the runtime threadpool
1 parent e20b0f0 commit 0b151d6

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/rt/mod.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! The runtime.
22
3+
use std::env;
34
use std::thread;
45

56
use once_cell::sync::Lazy;
@@ -12,10 +13,20 @@ pub struct Runtime {}
1213
/// The global runtime.
1314
pub static RUNTIME: Lazy<Runtime> = Lazy::new(|| {
1415
// Create an executor thread pool.
15-
let num_threads = num_cpus::get().max(1);
16-
for _ in 0..num_threads {
16+
17+
let thread_count = env::var("ASYNC_STD_THREAD_COUNT")
18+
.map(|env| {
19+
env.parse()
20+
.expect("ASYNC_STD_THREAD_COUNT must be a number")
21+
})
22+
.unwrap_or_else(|_| num_cpus::get())
23+
.max(1);
24+
25+
let thread_name = env::var("ASYNC_STD_THREAD_NAME").unwrap_or("async-std/runtime".to_string());
26+
27+
for _ in 0..thread_count {
1728
thread::Builder::new()
18-
.name("async-std/runtime".to_string())
29+
.name(thread_name.clone())
1930
.spawn(|| smol::run(future::pending::<()>()))
2031
.expect("cannot start a runtime thread");
2132
}

0 commit comments

Comments
 (0)