-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
- Loading branch information
Showing
5 changed files
with
8 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,18 @@ | ||
//! The runtime. | ||
use std::env; | ||
use std::thread; | ||
|
||
use once_cell::sync::Lazy; | ||
|
||
use crate::future; | ||
|
||
/// Dummy runtime struct. | ||
pub struct Runtime {} | ||
|
||
/// The global runtime. | ||
pub static RUNTIME: Lazy<Runtime> = Lazy::new(|| { | ||
// Create an executor thread pool. | ||
|
||
let thread_count = env::var("ASYNC_STD_THREAD_COUNT") | ||
.map(|env| { | ||
env.parse() | ||
.expect("ASYNC_STD_THREAD_COUNT must be a number") | ||
}) | ||
.unwrap_or_else(|_| num_cpus::get()) | ||
.max(1); | ||
|
||
let thread_name = | ||
env::var("ASYNC_STD_THREAD_NAME").unwrap_or_else(|_| "async-std/runtime".to_string()); | ||
let thread_name = env::var("ASYNC_STD_THREAD_NAME").unwrap_or_else(|_| "async-std/runtime".to_string()); | ||
async_global_executor::init_with_config(async_global_executor::GlobalExecutorConfig::default().with_env_var("ASYNC_STD_THREAD_COUNT").with_thread_name(thread_name)); | ||
|
||
for _ in 0..thread_count { | ||
thread::Builder::new() | ||
.name(thread_name.clone()) | ||
.spawn(|| crate::task::executor::run_global(future::pending::<()>())) | ||
.expect("cannot start a runtime thread"); | ||
} | ||
Runtime {} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters