1 //! The runtime. 2 3 use std::env; 4 use std::thread; 5 6 use once_cell::sync::Lazy; 7 8 use crate::future; 9 10 /// Dummy runtime struct. 11 pub struct Runtime {} 12 13 /// The global runtime. 14 pub static RUNTIME: Lazy<Runtime> = Lazy::new(|| { 15 // Create an executor thread pool. 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 { 28 thread::Builder::new() 29 .name(thread_name.clone()) 30 .spawn(|| crate::task::executor::run_global(future::pending::<()>())) 31 .expect("cannot start a runtime thread"); 32 } 33 Runtime {} 34 }); 35