File tree 1 file changed +14
-3
lines changed
1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 1
1
//! The runtime.
2
2
3
+ use std:: env;
3
4
use std:: thread;
4
5
5
6
use once_cell:: sync:: Lazy ;
@@ -12,10 +13,20 @@ pub struct Runtime {}
12
13
/// The global runtime.
13
14
pub static RUNTIME : Lazy < Runtime > = Lazy :: new ( || {
14
15
// 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 {
17
28
thread:: Builder :: new ( )
18
- . name ( "async-std/runtime" . to_string ( ) )
29
+ . name ( thread_name . clone ( ) )
19
30
. spawn ( || smol:: run ( future:: pending :: < ( ) > ( ) ) )
20
31
. expect ( "cannot start a runtime thread" ) ;
21
32
}
You can’t perform that action at this time.
0 commit comments