File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -575,4 +575,28 @@ mod tests {
575575 assert ! ( woken. load( Ordering :: SeqCst ) ) ;
576576 assert_eq ! ( Pin :: new( & mut future) . poll( & mut Context :: from_waker( & waker) ) , Poll :: Ready ( ( ) ) ) ;
577577 }
578+
579+ #[ test]
580+ fn test_multi_future_sleep ( ) {
581+ // Tests the `Sleeper` with multiple futures.
582+ let notifier_a = Notifier :: new ( ) ;
583+ let notifier_b = Notifier :: new ( ) ;
584+
585+ // Set both notifiers as woken without sleeping yet.
586+ notifier_a. notify ( ) ;
587+ notifier_b. notify ( ) ;
588+ Sleeper :: from_two_futures ( notifier_a. get_future ( ) , notifier_b. get_future ( ) ) . wait ( ) ;
589+
590+ // One future has woken us up, but the other should still have a pending notification.
591+ Sleeper :: from_two_futures ( notifier_a. get_future ( ) , notifier_b. get_future ( ) ) . wait ( ) ;
592+
593+ // However once we've slept twice, we should no longer have any pending notifications
594+ #[ cfg( feature = "std" ) ]
595+ assert ! ( !Sleeper :: from_two_futures( notifier_a. get_future( ) , notifier_b. get_future( ) )
596+ . wait_timeout( Duration :: from_millis( 10 ) ) ) ;
597+
598+ // Test ordering somewhat more.
599+ notifier_a. notify ( ) ;
600+ Sleeper :: from_two_futures ( notifier_a. get_future ( ) , notifier_b. get_future ( ) ) . wait ( ) ;
601+ }
578602}
You can’t perform that action at this time.
0 commit comments