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

Improve Request Queue Behavior #2 #700

Merged
merged 4 commits into from
Apr 27, 2023

Conversation

slugzero
Copy link
Contributor

This is the second PR to implement Koenkk/zigbee2mqtt#17177.
It is mostly a refactor to make future PRs more easily understandable. Apart from one fix to the previous PR, it does not change the current behavior (i.e. tests are only adapted to reflect the changes in the type definitions).

Changes:

  • Fix the send behavior for response messages: With the previous commit, response messages were not queued any more on send failure. But if the request queue was not empty, messages with sendWhen='fastpoll' and 'active' were still queued. Now response messages are always sent immediately and never get queued.
  • Make PendingRequest a class and rename it to Request. The ZclFrame is taken out of the func() as a separate member of the Request class, to make it accessible for message filtering. The class also includes some member functions to e.g. handle reject/resolve callbacks from multiple send requests.
  • Change pendingRequests from Array to Set, which handles asynchronous addition and removal of elements better, and allows to get rid of copying the pendingRequests array back and forth during sending. Apart from that, Set and Array should behave identically for us. A Set will not allow multiple identical elements, but queued requests should always differ, at least in their frame counter.
  • Introduce the new sendPolicies with defaults (but do not apply the policies yet).

I was not sure where the best place to put the new classes and types would be. So lmk if there is a better location and I will move them there.

@Koenkk Koenkk merged commit 7260392 into Koenkk:master Apr 27, 2023
@Koenkk
Copy link
Owner

Koenkk commented Apr 27, 2023

Thanks!

Something to be taken to the next pr: there is no need to prefix private class members with a _ (since in TS you use the private modifier)

@slugzero slugzero deleted the request-queue-fixes-1 branch April 28, 2023 08:02
@slugzero slugzero mentioned this pull request Dec 9, 2023
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

Successfully merging this pull request may close these issues.

2 participants