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

When does DeliveryToken return from .wait() #237

Open
dlips opened this issue Sep 23, 2024 · 1 comment
Open

When does DeliveryToken return from .wait() #237

dlips opened this issue Sep 23, 2024 · 1 comment

Comments

@dlips
Copy link

dlips commented Sep 23, 2024

Hello,

I am trying to check if my QoS 1 messages were delivered to my broker. From the documentation it is not clear to me, when the call to DeliveryToken::wait will return. Is it immediately when the message was sent to the broker or after the broker has successfully sent an ACK for that message?
In the C library you can register a callback for this with MQTTAsync_setDeliveryCompleteCallback(), see here but I cannot find the equivalent callback registration on the async_client. Is this planned to be implemented or does somebody know a workaround?

@fpagliughi
Copy link
Contributor

fpagliughi commented Sep 23, 2024

The token completes when the transaction is finished, So:

  • QoS 0, completes immediately.
  • QoS 1, completes when the PUBACK is received
  • QoS 2, completes when the PUBCOMP is received

I didn't expose all the callbacks because I have trying to move the library away from requiring them. Although they still make sense in C, they seem to make much less sense in a Rust async world. And they are extremely problematic with their limitations (no blocking calls) and tread synchronization issues.

But I could probably add the missing ones to make a full consistent API before moving on to a v2.0 that is more purely async/await.

I thought the MQTTAsync_setDeliveryCompleteCallback() was a bit redundant. I believe it could be done more uniformly by providing succes/failure callbacks, similar to the connect_with_callbaks().

For the moment, the solution is to spawn a task to wait on the Token (which implements the Future trait), and then fire a callback, if that's what you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants