File tree 4 files changed +31
-2
lines changed 4 files changed +31
-2
lines changed Original file line number Diff line number Diff line change 1
1
#![ feature( test) ]
2
2
3
+ #[ macro_use]
3
4
extern crate futures;
4
5
extern crate test;
5
6
@@ -106,7 +107,6 @@ impl Stream for TestSender {
106
107
Err ( _) => panic ! ( ) ,
107
108
Ok ( AsyncSink :: Ready ) => {
108
109
self . last += 1 ;
109
- assert_eq ! ( Ok ( Async :: Ready ( ( ) ) ) , self . tx. poll_complete( ) ) ;
110
110
Ok ( Async :: Ready ( Some ( self . last ) ) )
111
111
}
112
112
Ok ( AsyncSink :: NotReady ( _) ) => {
Original file line number Diff line number Diff line change @@ -649,7 +649,14 @@ impl<T> Sink for Sender<T> {
649
649
}
650
650
651
651
fn poll_complete ( & mut self ) -> Poll < ( ) , SendError < T > > {
652
- Ok ( Async :: Ready ( ( ) ) )
652
+ self . poll_ready ( )
653
+ // At this point, the value cannot be returned and `SendError`
654
+ // cannot be created with a `T` without breaking backwards
655
+ // comptibility. This means we cannot return an error.
656
+ //
657
+ // That said, there is also no guarantee that a `poll_complete`
658
+ // returning `Ok` implies the receiver sees the message.
659
+ . or_else ( |_| Ok ( ( ) . into ( ) ) )
653
660
}
654
661
655
662
fn close ( & mut self ) -> Poll < ( ) , SendError < T > > {
Original file line number Diff line number Diff line change @@ -548,3 +548,19 @@ fn try_send_fail() {
548
548
assert_eq ! ( rx. next( ) , Some ( Ok ( "goodbye" ) ) ) ;
549
549
assert ! ( rx. next( ) . is_none( ) ) ;
550
550
}
551
+
552
+ #[ test]
553
+ fn bounded_is_really_bounded ( ) {
554
+ use futures:: Async :: * ;
555
+ let ( mut tx, mut rx) = mpsc:: channel ( 0 ) ;
556
+ lazy ( || {
557
+ assert ! ( tx. start_send( 1 ) . unwrap( ) . is_ready( ) ) ;
558
+ // Not ready until we receive
559
+ assert ! ( !tx. poll_complete( ) . unwrap( ) . is_ready( ) ) ;
560
+ // Receive the value
561
+ assert_eq ! ( rx. poll( ) . unwrap( ) , Ready ( Some ( 1 ) ) ) ;
562
+ // Now the sender is ready
563
+ assert ! ( tx. poll_complete( ) . unwrap( ) . is_ready( ) ) ;
564
+ Ok :: < _ , ( ) > ( ( ) )
565
+ } ) . wait ( ) . unwrap ( ) ;
566
+ }
Original file line number Diff line number Diff line change @@ -392,6 +392,12 @@ fn fanout_backpressure() {
392
392
let ( item, right_recv) = right_recv. into_future ( ) . wait ( ) . unwrap ( ) ;
393
393
assert_eq ! ( item, Some ( 1 ) ) ;
394
394
assert ! ( flag. get( ) ) ;
395
+ let ( item, left_recv) = left_recv. into_future ( ) . wait ( ) . unwrap ( ) ;
396
+ assert_eq ! ( item, Some ( 2 ) ) ;
397
+ assert ! ( flag. get( ) ) ;
398
+ assert ! ( task. poll_future_notify( & flag, 0 ) . unwrap( ) . is_not_ready( ) ) ;
399
+ let ( item, right_recv) = right_recv. into_future ( ) . wait ( ) . unwrap ( ) ;
400
+ assert_eq ! ( item, Some ( 2 ) ) ;
395
401
match task. poll_future_notify ( & flag, 0 ) . unwrap ( ) {
396
402
Async :: Ready ( _) => {
397
403
} ,
You can’t perform that action at this time.
0 commit comments