File tree 5 files changed +8
-56
lines changed
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\""]
24
24
[features ]
25
25
default = [
26
26
" std" ,
27
- " async-executor" ,
27
+ " async-global- executor" ,
28
28
" async-io" ,
29
29
" async-task" ,
30
30
" blocking" ,
@@ -80,7 +80,7 @@ slab = { version = "0.4.2", optional = true }
80
80
surf = { version = " 1.0.3" , optional = true }
81
81
82
82
[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 " ] }
84
84
async-io = { version = " 1.0.1" , optional = true }
85
85
blocking = { version = " 1.0.0" , optional = true }
86
86
futures-lite = { version = " 1.0.0" , optional = true }
Original file line number Diff line number Diff line change 1
1
//! The runtime.
2
2
3
3
use std:: env;
4
- use std:: thread;
5
4
6
5
use once_cell:: sync:: Lazy ;
7
6
8
- use crate :: future;
9
-
10
7
/// Dummy runtime struct.
11
8
pub struct Runtime { }
12
9
13
10
/// The global runtime.
14
11
pub static RUNTIME : Lazy < Runtime > = Lazy :: new ( || {
15
12
// Create an executor thread pool.
16
13
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) ) ;
27
16
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
- }
34
17
Runtime { }
35
18
} ) ;
Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ impl Builder {
60
60
} ) ;
61
61
62
62
let task = wrapped. tag . task ( ) . clone ( ) ;
63
- let handle = crate :: task :: executor :: spawn ( wrapped) ;
63
+ let handle = async_global_executor :: spawn ( wrapped) ;
64
64
65
65
Ok ( JoinHandle :: new ( handle, task) )
66
66
}
@@ -80,7 +80,7 @@ impl Builder {
80
80
} ) ;
81
81
82
82
let task = wrapped. tag . task ( ) . clone ( ) ;
83
- let handle = crate :: task :: executor :: local ( wrapped) ;
83
+ let handle = async_global_executor :: spawn_local ( wrapped) ;
84
84
85
85
Ok ( JoinHandle :: new ( handle, task) )
86
86
}
Original file line number Diff line number Diff line change 1
- use std:: cell:: RefCell ;
2
1
use std:: future:: Future ;
3
2
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
-
27
3
pub ( crate ) fn run < F , T > ( future : F ) -> T
28
4
where
29
5
F : Future < Output = T > ,
30
6
{
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) )
39
8
}
40
9
41
10
/// 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> {
18
18
}
19
19
20
20
#[ cfg( not( target_os = "unknown" ) ) ]
21
- type InnerHandle < T > = async_executor :: Task < T > ;
21
+ type InnerHandle < T > = async_global_executor :: Task < T > ;
22
22
#[ cfg( target_arch = "wasm32" ) ]
23
23
type InnerHandle < T > = futures_channel:: oneshot:: Receiver < T > ;
24
24
You can’t perform that action at this time.
0 commit comments