@@ -181,6 +181,11 @@ impl<T: Serialize> Channel<T> {
181
181
self . on_demand_events . notify ( 1 ) ;
182
182
}
183
183
184
+ /// notify all OnDemand with an event listener
185
+ fn notify_all_on_demand ( & self ) {
186
+ self . on_demand_events . notify ( std:: usize:: MAX ) ;
187
+ }
188
+
184
189
/// create a listener so an OnDemand can get notice when demand has been requested
185
190
/// (a receiver tried to receive but the queue was empty)
186
191
fn on_demand_listen ( & self ) -> EventListener {
@@ -340,7 +345,13 @@ impl<T: Serialize> Sender<T> {
340
345
impl < T : Serialize > Clone for Sender < T > {
341
346
fn clone ( & self ) -> Self {
342
347
let count = self . channel . increment_sender_count ( ) ;
343
- info ! ( "Sender::clone: {} new count: {}" , self . name( ) , count) ;
348
+ let on_demand_count = self . channel . on_demand_count ( ) ;
349
+ info ! (
350
+ "Sender::Clone channel {}, new count: {}, on_demand_count: {}" ,
351
+ self . name( ) ,
352
+ count,
353
+ on_demand_count
354
+ ) ;
344
355
Sender {
345
356
channel : self . channel . clone ( ) ,
346
357
listener : None ,
@@ -353,8 +364,15 @@ impl<T: Serialize> Clone for Sender<T> {
353
364
impl < T : Serialize > Drop for Sender < T > {
354
365
fn drop ( & mut self ) {
355
366
let count = self . channel . decrement_sender_count ( ) ;
356
- info ! ( "Sender::drop: {} new count: {}" , self . name( ) , count) ;
367
+ let on_demand_count = self . channel . on_demand_count ( ) ;
368
+ info ! (
369
+ "Sender::Drop channel {}, new count: {}, on_demand_count: {}" ,
370
+ self . name( ) ,
371
+ count,
372
+ on_demand_count
373
+ ) ;
357
374
if count == 0 {
375
+ info ! ( "Sender::Drop channel {}, notify_all_receivers" , self . name( ) ) ;
358
376
self . channel . notify_all_receivers ( ) ;
359
377
}
360
378
}
@@ -431,7 +449,7 @@ impl<T: Serialize> Sink<T> for Sender<T> {
431
449
if self . no_receivers ( ) {
432
450
self . listener = None ;
433
451
debug ! (
434
- "Sink for Sender:poll_ready {} no_receivers, length: $ {}" ,
452
+ "Sink for Sender:poll_ready {} no_receivers, length: {}" ,
435
453
self . name( ) ,
436
454
self . len( )
437
455
) ;
@@ -531,9 +549,10 @@ pub struct Receiver<T: Serialize> {
531
549
impl < T : Serialize > Clone for Receiver < T > {
532
550
fn clone ( & self ) -> Self {
533
551
let count = self . channel . increment_receiver_count ( ) ;
552
+ let on_demand_count = self . channel . on_demand_count ( ) ;
534
553
debug ! (
535
- "Receiver:Clone cloning channel {}, new count: {}" ,
536
- self . channel. name, count
554
+ "Receiver:Clone channel {}, new count: {}, on_demand_count : {}" ,
555
+ self . channel. name, count, on_demand_count
537
556
) ;
538
557
Receiver {
539
558
channel : self . channel . clone ( ) ,
@@ -547,9 +566,10 @@ impl<T: Serialize> Clone for Receiver<T> {
547
566
impl < T : Serialize > Drop for Receiver < T > {
548
567
fn drop ( & mut self ) {
549
568
let new_count = self . channel . decrement_receiver_count ( ) ;
569
+ let on_demand_count = self . channel . on_demand_count ( ) ;
550
570
debug ! (
551
- "Receiver:Drop channel {}, new count: {}" ,
552
- self . channel. name, new_count
571
+ "Receiver:Drop channel {}, new count: {}, on_demand_count: {} " ,
572
+ self . channel. name, new_count, on_demand_count
553
573
) ;
554
574
if new_count == 0 {
555
575
// notify all senders so they will see there are no more receivers
@@ -558,6 +578,8 @@ impl<T: Serialize> Drop for Receiver<T> {
558
578
"Receiver:Drop channel {}, notify_all_senders" ,
559
579
self . channel. name
560
580
) ;
581
+ // When there are no more receivers we need to notify the on_demand in addition to the normal senders
582
+ self . channel . notify_all_on_demand ( ) ;
561
583
self . channel . notify_all_senders ( ) ;
562
584
}
563
585
}
@@ -674,6 +696,10 @@ impl<T: Serialize + Send + 'static> Stream for OnDemandReceiver<T> {
674
696
self . channel. len( )
675
697
) ;
676
698
self . listener = None ;
699
+ debug ! (
700
+ "OnDemandReceiver::poll_next {} listener: None" ,
701
+ self . channel. name
702
+ ) ;
677
703
return Poll :: Ready ( None ) ;
678
704
}
679
705
0 commit comments