Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(acked): add a non consuming method to the notice #934

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions rumqttc/src/notice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ impl NoticeFuture {
pub async fn wait_async(self) -> NoticeResult {
self.0.await?
}

/// Attempts to check if the broker acknowledged the packet, without blocking the current thread
/// or consuming the notice.
///
/// It will return [`None`] if the packet wasn't acknowledged.
///
/// Multiple calls to this functions can fail with [`NoticeError::Recv`] if the notice was
/// already waited and the packet was already acknowledged and [`Some`] value was returned.
pub fn try_wait(&mut self) -> Option<NoticeResult> {
match self.0.try_recv() {
Ok(res) => Some(res),
Err(oneshot::error::TryRecvError::Closed) => Some(Err(NoticeError::Recv)),
Err(oneshot::error::TryRecvError::Empty) => None,
}
}
}

#[derive(Debug)]
Expand Down