Skip to content

Commit 7ec73f4

Browse files
ids1024notgull
authored andcommitted
sources/channel: Ping on drop of last instance of SyncSender
Presumably this should behave like `Sender`, but only ping once all clones have been dropped. This should achieve that.
1 parent 893761e commit 7ec73f4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/sources/channel.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use std::cmp;
1212
use std::fmt;
1313
use std::ops;
14-
use std::sync::mpsc;
14+
use std::sync::{mpsc, Arc};
1515

1616
use crate::{EventSource, Poll, PostAction, Readiness, Token, TokenFactory};
1717

@@ -85,7 +85,9 @@ impl<T> Sender<T> {
8585
#[derive(Debug)]
8686
pub struct SyncSender<T> {
8787
sender: mpsc::SyncSender<T>,
88-
ping: Ping,
88+
// Dropped after `sender` so receiver is guaranteed to get `Disconnected`
89+
// after ping.
90+
ping: Arc<PingOnDrop>,
8991
}
9092

9193
impl<T> Clone for SyncSender<T> {
@@ -195,7 +197,7 @@ pub fn sync_channel<T>(bound: usize) -> (SyncSender<T>, Channel<T>) {
195197
(
196198
SyncSender {
197199
sender,
198-
ping: ping.clone(),
200+
ping: Arc::new(PingOnDrop(ping.clone())),
199201
},
200202
Channel {
201203
receiver,

0 commit comments

Comments
 (0)