Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There are a few historical PRs that I looked through related to this PR: https://github.com/mqttjs/MQTT.js/pull/771/files
https://github.com/mqttjs/MQTT.js/pull/827/files
This PR addresses some of the flakiness in tests seen in the build system, both by adding a minor adjustment to a test but more importantly by adjusting the way
end()
calls it's callbacks.If the
end()
method is disconnecting, it will simply return and never invoke the callback passed to it... This seems like flawed behavior since the callback passed is unique to that call toend()
. This PR changes howend()
works, so that the callback is invoked regardless if the client is disconnecting or not. Additionally, it removes the use of arguments that was introduced in the above two PRs, as I could find no logical justification for the use of arguments over actual defined parameters? Finally, I could find no logical justification of just returning the arguments object as a parameter of the callback, so that is changed where the callback is simply invoked.I thought about adding information into the callback, like if the client is
disconnecting
,connected
, ordisconnected
, but because theend
event is emitted once the stores are closed we can use that in tandem with the callback to determine if the client is actually disconnected. If the callback is invoked on a call to end but theend
event has not yet been emitted then the user can know that the client is in the process of disconnecting but has not fully disconnected yet.