File tree 2 files changed +17
-0
lines changed
2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -214,12 +214,19 @@ impl<T> Inner<T> {
214
214
// and deadlock might be possible, as was observed in
215
215
// https://github.com/rust-lang-nursery/futures-rs/pull/219.
216
216
self . complete . store ( true , SeqCst ) ;
217
+
217
218
if let Some ( mut slot) = self . rx_task . try_lock ( ) {
218
219
if let Some ( task) = slot. take ( ) {
219
220
drop ( slot) ;
220
221
task. wake ( ) ;
221
222
}
222
223
}
224
+
225
+ // If we registered a task for cancel notification drop it to reduce
226
+ // spurious wakeups
227
+ if let Some ( mut slot) = self . tx_task . try_lock ( ) {
228
+ drop ( slot. take ( ) ) ;
229
+ }
223
230
}
224
231
225
232
fn close_rx ( & self ) {
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ use futures::channel::oneshot::{self, Sender};
4
4
use futures:: executor:: block_on;
5
5
use futures:: future:: { Future , FutureExt , poll_fn} ;
6
6
use futures:: task:: { Context , Poll } ;
7
+ use futures_test:: task:: panic_waker_ref;
7
8
use std:: pin:: Pin ;
8
9
use std:: sync:: mpsc;
9
10
use std:: thread;
@@ -69,6 +70,15 @@ fn cancel_lots() {
69
70
t. join ( ) . unwrap ( ) ;
70
71
}
71
72
73
+ #[ test]
74
+ fn cancel_after_sender_drop_doesnt_notify ( ) {
75
+ let ( mut tx, rx) = oneshot:: channel :: < u32 > ( ) ;
76
+ let mut cx = Context :: from_waker ( panic_waker_ref ( ) ) ;
77
+ assert_eq ! ( tx. poll_cancel( & mut cx) , Poll :: Pending ) ;
78
+ drop ( tx) ;
79
+ drop ( rx) ;
80
+ }
81
+
72
82
#[ test]
73
83
fn close ( ) {
74
84
let ( mut tx, mut rx) = oneshot:: channel :: < u32 > ( ) ;
You can’t perform that action at this time.
0 commit comments