Skip to content

Commit 413ca84

Browse files
committed
add a thread name env var as well
1 parent d6455ab commit 413ca84

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/rt/mod.rs

+11-4
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,14 +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 = std::env::var("ASYNC_STD_RT_THREADS")
16-
.map(|env| env.parse().expect("ASYNC_STD_RT_THREADS must be a number"))
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+
})
1722
.unwrap_or_else(|_| num_cpus::get())
1823
.max(1);
1924

20-
for _ in 0..num_threads {
25+
let thread_name = env::var("ASYNC_STD_THREAD_NAME").unwrap_or("async-std/runtime".to_string());
26+
27+
for _ in 0..thread_count {
2128
thread::Builder::new()
22-
.name("async-std/runtime".to_string())
29+
.name(thread_name.clone())
2330
.spawn(|| smol::run(future::pending::<()>()))
2431
.expect("cannot start a runtime thread");
2532
}

0 commit comments

Comments
 (0)