Skip to content

Commit c93db8a

Browse files
Merge pull request #1252 from hberntsen/0.1
Backport Sender::is_closed method
2 parents b6435ff + dd6ebbd commit c93db8a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/sync/mpsc/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,11 @@ impl<T> Sender<T> {
600600
Ok(self.poll_unparked(true))
601601
}
602602

603+
/// Returns whether this channel is closed without needing a context.
604+
pub fn is_closed(&self) -> bool {
605+
!decode_state(self.inner.state.load(SeqCst)).is_open
606+
}
607+
603608
fn poll_unparked(&mut self, do_park: bool) -> Async<()> {
604609
// First check the `maybe_parked` variable. This avoids acquiring the
605610
// lock in most cases
@@ -665,6 +670,11 @@ impl<T> Sink for Sender<T> {
665670
}
666671

667672
impl<T> UnboundedSender<T> {
673+
/// Returns whether this channel is closed without needing a context.
674+
pub fn is_closed(&self) -> bool {
675+
self.0.is_closed()
676+
}
677+
668678
/// Sends the provided message along this channel.
669679
///
670680
/// This is an unbounded sender, so this function differs from `Sink::send`

0 commit comments

Comments
 (0)