File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -183,7 +183,14 @@ cfg_rt! {
183
183
#[ track_caller]
184
184
pub ( super ) fn with_scheduler<R >( f: impl FnOnce ( Option <& scheduler:: Context >) -> R ) -> R {
185
185
let mut f = Some ( f) ;
186
- CONTEXT . try_with( |c| c. scheduler. with( f. take( ) . unwrap( ) ) )
186
+ CONTEXT . try_with( |c| {
187
+ let f = f. take( ) . unwrap( ) ;
188
+ if matches!( c. runtime. get( ) , EnterRuntime :: Entered { .. } ) {
189
+ c. scheduler. with( f)
190
+ } else {
191
+ f( None )
192
+ }
193
+ } )
187
194
. unwrap_or_else( |_| ( f. take( ) . unwrap( ) ) ( None ) )
188
195
}
189
196
Original file line number Diff line number Diff line change 1
1
#![ allow( unknown_lints, unexpected_cfgs) ]
2
- #![ cfg( all( feature = "full" , tokio_unstable) ) ]
2
+ #![ cfg( all( feature = "full" , not ( target_os = "wasi" ) , tokio_unstable) ) ]
3
3
4
4
use tokio:: task;
5
5
use tokio_test:: task:: spawn;
@@ -15,3 +15,11 @@ fn yield_now_outside_of_runtime() {
15
15
assert ! ( task. is_woken( ) ) ;
16
16
assert ! ( task. poll( ) . is_ready( ) ) ;
17
17
}
18
+
19
+ #[ tokio:: test( flavor = "multi_thread" ) ]
20
+ async fn yield_now_external_executor_and_block_in_place ( ) {
21
+ let j = tokio:: spawn ( async {
22
+ task:: block_in_place ( || futures:: executor:: block_on ( task:: yield_now ( ) ) ) ;
23
+ } ) ;
24
+ j. await . unwrap ( ) ;
25
+ }
You can’t perform that action at this time.
0 commit comments