-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
add a Disconnecting event to MqttClient #1964
Conversation
@chkr1011 Could you please take a look? |
What is the purpose of the new event? To me it looks like a copy of the already existing "Disconnected" event but it is fired before doing the actual disconnect!? Do you have a sample what it is used for? |
It's the same reason why we have a Connecting event, which happens right after the connection status is transitioned into Connecting but the work of connecting to the server has not started yet, even though we have a Connected event. Disconnected happens after everything is done, while Disconnecting happens before that. That is the difference. With this new event, I can get an accurate reason code from the DISCONNECT packet when PublishAsync() errors out, because the newly added DISCONNECTING event is invoked synchronously before all the resources of the client are released. Here is an example: #1963. |
Basically it guarantees us an early access to the reason code in the DISCONNECT packet when server disconnects the client. |
@chkr1011 could you let me know if my comments address your concern? |
@chkr1011 could you take another look? |
@chkr1011 Addressed your comments. Could you please take another look? |
Thank you for your explanation. In my opinion there should be no new event at all because you have to change to do anything to avoid disconnecting etc. We might consider exposing the information in the Publish as well. Lets imagine the publish does not work and gets an error. We might add a property to the disconnection information so that you have it in the catch clause of the Publish method. Then you don't need to synchronize the data from one event handler to a field and access that field from a different event handler. That do you think about that? |
@chkr1011 that's even better. If I understand correctly, you are saying we should catch the exception from Publish, and re-throw a specific exception type (for example, MqttClientUnexpectedDisconnectReceivedException) that could contain the info from the disconnect packet. |
add a Disconnecting event to MqttClient