File tree Expand file tree Collapse file tree 5 files changed +8
-56
lines changed Expand file tree Collapse file tree 5 files changed +8
-56
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ rustdoc-args = ["--cfg", "feature=\"docs\""]
2424[features ]
2525default = [
2626 " std" ,
27- " async-executor" ,
27+ " async-global- executor" ,
2828 " async-io" ,
2929 " async-task" ,
3030 " blocking" ,
@@ -80,7 +80,7 @@ slab = { version = "0.4.2", optional = true }
8080surf = { version = " 1.0.3" , optional = true }
8181
8282[target .'cfg(not(target_os = "unknown"))' .dependencies ]
83- async-executor = { version = " 1.0.0 " , optional = true }
83+ async-global- executor = { version = " 1.0.1 " , optional = true , features = [ " async-io " ] }
8484async-io = { version = " 1.0.1" , optional = true }
8585blocking = { version = " 1.0.0" , optional = true }
8686futures-lite = { version = " 1.0.0" , optional = true }
Original file line number Diff line number Diff line change 11//! The runtime.
22
33use std:: env;
4- use std:: thread;
54
65use once_cell:: sync:: Lazy ;
76
8- use crate :: future;
9-
107/// Dummy runtime struct.
118pub struct Runtime { }
129
1310/// The global runtime.
1411pub static RUNTIME : Lazy < Runtime > = Lazy :: new ( || {
1512 // Create an executor thread pool.
1613
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 =
26- env:: var ( "ASYNC_STD_THREAD_NAME" ) . unwrap_or_else ( |_| "async-std/runtime" . to_string ( ) ) ;
14+ let thread_name = env:: var ( "ASYNC_STD_THREAD_NAME" ) . unwrap_or_else ( |_| "async-std/runtime" . to_string ( ) ) ;
15+ async_global_executor:: init_with_config ( async_global_executor:: GlobalExecutorConfig :: default ( ) . with_env_var ( "ASYNC_STD_THREAD_COUNT" ) . with_thread_name ( thread_name) ) ;
2716
28- for _ in 0 ..thread_count {
29- thread:: Builder :: new ( )
30- . name ( thread_name. clone ( ) )
31- . spawn ( || crate :: task:: executor:: run_global ( future:: pending :: < ( ) > ( ) ) )
32- . expect ( "cannot start a runtime thread" ) ;
33- }
3417 Runtime { }
3518} ) ;
Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ impl Builder {
6060 } ) ;
6161
6262 let task = wrapped. tag . task ( ) . clone ( ) ;
63- let handle = crate :: task :: executor :: spawn ( wrapped) ;
63+ let handle = async_global_executor :: spawn ( wrapped) ;
6464
6565 Ok ( JoinHandle :: new ( handle, task) )
6666 }
@@ -80,7 +80,7 @@ impl Builder {
8080 } ) ;
8181
8282 let task = wrapped. tag . task ( ) . clone ( ) ;
83- let handle = crate :: task :: executor :: local ( wrapped) ;
83+ let handle = async_global_executor :: spawn_local ( wrapped) ;
8484
8585 Ok ( JoinHandle :: new ( handle, task) )
8686 }
Original file line number Diff line number Diff line change 1- use std:: cell:: RefCell ;
21use std:: future:: Future ;
32
4- static GLOBAL_EXECUTOR : once_cell:: sync:: Lazy < async_executor:: Executor > = once_cell:: sync:: Lazy :: new ( async_executor:: Executor :: new) ;
5-
6- thread_local ! {
7- static EXECUTOR : RefCell <async_executor:: LocalExecutor > = RefCell :: new( async_executor:: LocalExecutor :: new( ) ) ;
8- }
9-
10- pub ( crate ) fn spawn < F , T > ( future : F ) -> async_executor:: Task < T >
11- where
12- F : Future < Output = T > + Send + ' static ,
13- T : Send + ' static ,
14- {
15- GLOBAL_EXECUTOR . spawn ( future)
16- }
17-
18- #[ cfg( feature = "unstable" ) ]
19- pub ( crate ) fn local < F , T > ( future : F ) -> async_executor:: Task < T >
20- where
21- F : Future < Output = T > + ' static ,
22- T : ' static ,
23- {
24- EXECUTOR . with ( |executor| executor. borrow ( ) . spawn ( future) )
25- }
26-
273pub ( crate ) fn run < F , T > ( future : F ) -> T
284where
295 F : Future < Output = T > ,
306{
31- EXECUTOR . with ( |executor| enter ( || async_io:: block_on ( executor. borrow ( ) . run ( future) ) ) )
32- }
33-
34- pub ( crate ) fn run_global < F , T > ( future : F ) -> T
35- where
36- F : Future < Output = T > ,
37- {
38- enter ( || async_io:: block_on ( GLOBAL_EXECUTOR . run ( future) ) )
7+ enter ( || async_global_executor:: block_on ( future) )
398}
409
4110/// Enters the tokio context if the `tokio` feature is enabled.
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ pub struct JoinHandle<T> {
1818}
1919
2020#[ cfg( not( target_os = "unknown" ) ) ]
21- type InnerHandle < T > = async_executor :: Task < T > ;
21+ type InnerHandle < T > = async_global_executor :: Task < T > ;
2222#[ cfg( target_arch = "wasm32" ) ]
2323type InnerHandle < T > = futures_channel:: oneshot:: Receiver < T > ;
2424
You can’t perform that action at this time.
0 commit comments