Skip to content

Commit

Permalink
consider also open triggered case
Browse files Browse the repository at this point in the history
  • Loading branch information
glendc committed Mar 8, 2024
1 parent 08614b6 commit 640a6ed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl ShutdownGuard {
///
/// Use [`ShutdownGuard::cancelled`] to wait for the cancellation (shutdown) to be requested.
#[inline]
pub fn cancelled_peek(&self) -> bool {
pub fn cancelled_peek(&mut self) -> bool {
self.0.cancelled_peek()
}

Expand Down Expand Up @@ -207,7 +207,7 @@ impl WeakShutdownGuard {
///
/// Use [`WeakShutdownGuard::cancelled`] to wait for the cancellation (shutdown) to be requested.
#[inline]
pub fn cancelled_peek(&self) -> bool {
pub fn cancelled_peek(&mut self) -> bool {
self.trigger_rx.closed()
}

Expand Down
11 changes: 9 additions & 2 deletions src/trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ enum SubscriberState {
}

impl Subscriber {
pub(crate) fn triggered(&self) -> bool {
self.state.load(Ordering::SeqCst)
}

/// Returns the state of the Subscriber,
/// which is used as a main driver in the Receiver's `Future::poll` implementation.
///
Expand Down Expand Up @@ -148,8 +152,11 @@ impl Receiver {
}
}

pub(crate) fn closed(&self) -> bool {
matches!(self.state, ReceiverState::Closed)
pub(crate) fn closed(&mut self) -> bool {
match &self.state {
ReceiverState::Open { sub, .. } => sub.triggered(),
ReceiverState::Closed => true,
}
}
}

Expand Down

0 comments on commit 640a6ed

Please sign in to comment.