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

Improves asyncutils/Debounce #7189

Merged
merged 3 commits into from
Sep 8, 2020
Merged

Improves asyncutils/Debounce #7189

merged 3 commits into from
Sep 8, 2020

Conversation

farazdagi
Copy link
Contributor

@farazdagi farazdagi commented Sep 8, 2020

What type of PR is this?

Other/Refactoring/Minor fixing

What does this PR do? Why is it needed?

  • Better implementation of context cancelling: context cancelling channel was listened only in inner loop, making it impossible to get out of the function if no incoming events are sent (in this PR: we can create debouncer, never send any event to it, and on context cancellation -- debouncer stops and returns).
  • time.After aggregated timer channels, and depending on the rate of incoming events it might be a problem (too many resources to garbage collect). I've changed routine to use explicit time.Timer.C instead -- so at the moment only a single timer channel is open at a time. And when we need to reset (on every incoming event), previous timer is stopped, and new timer is created (which is exactly what happened when we used time.After() with additional benefit of stopping the previous timer before creating a new one).
  • Fixes race condition in test: if you run tests many times over, eventually you will step into failed test (when timer is almost triggered, but not fast enough and test assertions already is testing the result).
  • Tests all the scenarios fully (no events, cancelling using inner loop, cancelling using outer loop, single handler invocation, multiple invocations -- to make sure that debouncer's outer loop works correctly).

Which issues(s) does this PR fix?

Other notes for review

@farazdagi farazdagi requested a review from rauljordan September 8, 2020 10:53
@farazdagi farazdagi self-assigned this Sep 8, 2020
@farazdagi farazdagi marked this pull request as ready for review September 8, 2020 11:09
@farazdagi farazdagi requested a review from a team as a code owner September 8, 2020 11:09
@farazdagi farazdagi requested review from shayzluf and rkapka September 8, 2020 11:09
@codecov
Copy link

codecov bot commented Sep 8, 2020

Codecov Report

Merging #7189 into master will decrease coverage by 0.12%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #7189      +/-   ##
==========================================
- Coverage   61.77%   61.65%   -0.13%     
==========================================
  Files         410      410              
  Lines       32678    32556     -122     
==========================================
- Hits        20188    20073     -115     
- Misses       9613     9617       +4     
+ Partials     2877     2866      -11     

@farazdagi farazdagi changed the title Improves asyncutils/debounce Improves asyncutils/Debounce Sep 8, 2020
Copy link
Contributor

@rauljordan rauljordan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Learned a lot from reading this code, thanks @farazdagi !

@prylabs-bulldozer prylabs-bulldozer bot merged commit 51f2cc1 into master Sep 8, 2020
@delete-merged-branch delete-merged-branch bot deleted the fix-debounce-timer branch September 8, 2020 14:49
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