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

Lumeo rust utilities acked #1

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
PkidError when no pkid
Devdutt Shenoi authored and FSMaxB committed Jun 20, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 22276a41c099ba4056ef2fb368f852dbef2c792f
2 changes: 1 addition & 1 deletion rumqttc/examples/pkid_promise.rs
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ async fn requests(client: AsyncClient) {
.unwrap().wait_async(),
);
}
Some(Ok(Some(pkid))) = joins.join_next() => {
Some(Ok(Ok(pkid))) = joins.join_next() => {
println!("Pkid: {:?}", pkid);
}
else => break,
2 changes: 1 addition & 1 deletion rumqttc/examples/pkid_promise_v5.rs
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ async fn requests(client: AsyncClient) {
.unwrap().wait_async(),
);
}
Some(Ok(Some(pkid))) = joins.join_next() => {
Some(Ok(Ok(pkid))) = joins.join_next() => {
println!("Pkid: {:?}", pkid);
}
else => break,
21 changes: 17 additions & 4 deletions rumqttc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -168,19 +168,32 @@ pub struct PkidPromise {
inner: oneshot::Receiver<Pkid>,
}

#[derive(Debug, thiserror::Error)]
pub enum PkidError {
#[error("Eventloop dropped Sender: {0}")]
Recv(#[from] oneshot::error::RecvError),
}

impl PkidPromise {
pub fn new(inner: oneshot::Receiver<Pkid>) -> Self {
Self { inner }
}

/// Wait for the pkid to resolve by blocking the current thread
pub fn wait(self) -> Option<Pkid> {
self.inner.blocking_recv().ok()
///
/// # Panics
/// Panics if called in an async context
pub fn wait(self) -> Result<Pkid, PkidError> {
let pkid = self.inner.blocking_recv()?;

Ok(pkid)
}

/// Await pkid resolution without blocking the current thread
pub async fn wait_async(self) -> Option<Pkid> {
self.inner.await.ok()
pub async fn wait_async(self) -> Result<Pkid, PkidError> {
let pkid = self.inner.await?;

Ok(pkid)
}
}