pub fn init_with_config(config: GlobalExecutorConfig) {
    if !GLOBAL_EXECUTOR_INIT.compare_and_swap(false, true, Ordering::AcqRel) {
        let num_cpus = std::env::var(config.env_var.unwrap_or("ASYNC_GLOBAL_EXECUTOR_THREADS"))
            .ok()
            .and_then(|threads| threads.parse().ok())
            .or(config.default_threads)
            .unwrap_or_else(num_cpus::get)
            .max(1);
        for n in 1..=num_cpus {
            thread::Builder::new()
                .name(config.thread_name.clone().unwrap_or_else(|| {
                    format!(
                        "{}{}",
                        config
                            .thread_name_prefix
                            .unwrap_or("async-global-executor-"),
                        n
                    )
                }))
                .spawn(|| loop {
                    let _ = std::panic::catch_unwind(|| {
                        LOCAL_EXECUTOR.with(|executor| {
                            let local = executor.run(future::pending::<()>());
                            let global = GLOBAL_EXECUTOR.run(future::pending::<()>());
                            reactor::block_on(future::or(local, global))
                        })
                    });
                })
                .expect("cannot spawn executor thread");
        }
    }
}
/// Init the global executor, spawning as many threads as specified or
/// the value specified by the specified environment variable.
///
/// # Examples
///
/// ```
/// async_global_executor::init_with_config(
///     async_global_executor::GlobalExecutorConfig::default()
///         .with_env_var("NUMBER_OF_THREADS")
///         .with_default_threads(4)
///         .with_thread_name_prefix("thread-")
/// );
/// ```
Init the global executor, spawning as many threads as specified or
the value specified by the specified environment variable.
Init the global executor spawning as many threads as specified or the value specified by the specified environment variable .
pub fn init_with_config(config: GlobalExecutorConfig) {
    if !GLOBAL_EXECUTOR_INIT.compare_and_swap(false, true, Ordering::AcqRel) {
        let num_cpus = std::env::var(config.env_var.unwrap_or("ASYNC_GLOBAL_EXECUTOR_THREADS"))
            .ok()
            .and_then(|threads| threads.parse().ok())
            .or(config.default_threads)
            .unwrap_or_else(num_cpus::get)
            .max(1);
        for n in 1..=num_cpus {
            thread::Builder::new()
                .name(config.thread_name.clone().unwrap_or_else(|| {
                    format!(
                        "{}{}",
                        config
                            .thread_name_prefix
                            .unwrap_or("async-global-executor-"),
                        n
                    )
                }))
                .spawn(|| loop {
                    let _ = std::panic::catch_unwind(|| {
                        LOCAL_EXECUTOR.with(|executor| {
                            let local = executor.run(future::pending::<()>());
                            let global = GLOBAL_EXECUTOR.run(future::pending::<()>());
                            reactor::block_on(future::or(local, global))
                        })
                    });
                })
                .expect("cannot spawn executor thread");
        }
    }
}
pub fn init_with_config ( config : GlobalExecutorConfig ) { if ! GLOBAL_EXECUTOR_INIT . compare_and_swap ( false , true , Ordering :: AcqRel ) { let num_cpus = std :: env :: var ( config . env_var . unwrap_or ( " " ) ) . ok ( ) . and_then ( | threads | threads . parse ( ) . ok ( ) ) . or ( config . default_threads ) . unwrap_or_else ( num_cpus :: get ) . max ( 1 ) ; for n in 1 ..= num_cpus { thread :: Builder :: new ( ) . name ( config . thread_name . clone ( ) . unwrap_or_else ( | | { format ! ( " " config thread_name_prefix unwrap_or ( " " ) n ) } ) ) . spawn ( | | loop { let _ = std :: panic :: catch_unwind ( | | { LOCAL_EXECUTOR . with ( | executor | { let local = executor . run ( future :: pending :: < ( ) > ( ) ) ; let global = GLOBAL_EXECUTOR . run ( future :: pending :: < ( ) > ( ) ) ; reactor :: block_on ( future :: or ( local , global ) ) } ) } ) ; } ) . expect ( " " ) ; } } }
Init the global executor, spawning as many threads as specified or
the value specified by the specified environment variable.
Init the global executor spawning as many threads as specified or the value specified by the specified environment variable .
config
GlobalExecutorConfig
config
GlobalExecutorConfig
examples
```
async_global_executor::init_with_config(
async_global_executor::GlobalExecutorConfig::default()
.with_env_var("NUMBER_OF_THREADS")
.with_default_threads(4)
.with_thread_name_prefix("thread-")
);
```
` ` ` async_global_executor :: init_with_config ( async_global_executor :: GlobalExecutorConfig :: default () . with_env_var ( " NUMBER_OF_THREADS " ) . with_default_threads ( 4 ) . with_thread_name_prefix ( " thread - " ) ) ; ` ` `