File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -346,6 +346,22 @@ impl Handle {
346346 }
347347 }
348348
349+ pub async fn yield_now ( & self ) {
350+ match self {
351+ Self :: Tokio ( _) => tokio:: task:: yield_now ( ) . await ,
352+ #[ cfg( feature = "simulation" ) ]
353+ Self :: Simulation ( handle) => handle. yield_now ( ) . await ,
354+ }
355+ }
356+
357+ pub fn now ( & self ) -> Duration {
358+ match self {
359+ Self :: Tokio ( _) => panic ! ( "Handle::now is only supported by the simulation runtime" ) ,
360+ #[ cfg( feature = "simulation" ) ]
361+ Self :: Simulation ( handle) => handle. now ( ) ,
362+ }
363+ }
364+
349365 pub fn block_on < F : Future > ( & self , future : F ) -> F :: Output {
350366 match self {
351367 Self :: Tokio ( handle) => tokio:: task:: block_in_place ( || handle. block_on ( future) ) ,
@@ -381,10 +397,7 @@ mod tests {
381397 drop ( jh) ;
382398
383399 // Yield so the spawned task gets polled.
384- handle
385- . timeout ( std:: time:: Duration :: from_millis ( 50 ) , async { } )
386- . await
387- . ok ( ) ;
400+ handle. yield_now ( ) . await ;
388401 } ) ;
389402
390403 assert ! ( flag. load( Ordering :: Acquire ) ) ;
Original file line number Diff line number Diff line change @@ -352,6 +352,11 @@ impl Handle {
352352 self . executor . time . timeout ( duration, future) . await
353353 }
354354
355+ /// Yield this task back to the simulation scheduler once.
356+ pub async fn yield_now ( & self ) {
357+ yield_now ( ) . await
358+ }
359+
355360 pub fn block_on < F : Future > ( & self , future : F ) -> F :: Output {
356361 self . executor . block_on ( future)
357362 }
You can’t perform that action at this time.
0 commit comments