-
Notifications
You must be signed in to change notification settings - Fork 93
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
DebouncedChan: When channel is firing continously, only fire once per period #222
Conversation
// of +/-2 to allow the channel to be off by two cycles in either direction. | ||
// By running at `-count 1000` or so I can usually reproduce an | ||
// off-by-one-or-two cycle. | ||
expectedNumSignal := int(math.Round(float64(testTime)/float64(cooldown))) + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the key test change here: notice how we drop the *2
expected invocations.
af5b789
to
0afda9e
Compare
0afda9e
to
a43a1d7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fantastic 🙌
@@ -79,25 +83,52 @@ func (d *DebouncedChan) nonBlockingSendOnC() { | |||
} | |||
} | |||
|
|||
func (d *DebouncedChan) waitForTimer() { | |||
// Waits for the timer to be fired, and loops as long as Call invocations comes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Waits for the timer to be fired, and loops as long as Call invocations comes | |
// Waits for the timer to be fired, and loops as long as Call invocations come |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, thanks. Fixed!
Oh, do you think this is changelog worthy? I would list it as a minor fix in there. |
… period This one's a follow up to #221. `DebouncedChan` previously had a bit of a bug where if `Call` was being invoked continuously, it was firing more often than expected: once for an initial `Call`, and then again when the timer elapsed. Here, we modify the implementation so that under a continuous fire situation, `DebouncedChan` will fire once initially, and then once every time the timer elapses at the end of each period. This reduces the number of emits on `C` from 2N+1 to the more expected N+1 (the +1 being the initial fire). We accomplish this by entering a loop that waits on the timer when receiving an initial `Call`, with the loop continuously resetting and waiting on the timer after each time it fires, sending on `C` each time the period elapses where a `Call` invocation came in. If a period elapses without a new `Call` coming in, the timer stops, the loop returns and `DebouncedChan` returns to its initial state.
a43a1d7
to
d593ae1
Compare
Yeah I was having a hard time deciding whether to mention it or not. Added an entry now. |
Thanks! |
This one's a follow up to #221.
DebouncedChan
previously had a bit ofa bug where if
Call
was being invoked continuously, it was firing moreoften than expected: once for an initial
Call
, and then again when thetimer elapsed.
Here, we modify the implementation so that under a continuous fire
situation,
DebouncedChan
will fire once initially, and then once everytime the timer elapses at the end of each period. This reduces the
number of emits on
C
from 2N+1 to the more expected N+1 (the +1 beingthe initial fire).
We accomplish this by entering a loop that waits on the timer when
receiving an initial
Call
, with the loop continuously resetting andwaiting on the timer after each time it fires, sending on
C
each timethe period elapses where a
Call
invocation came in. If a periodelapses without a new
Call
coming in, the timer stops, the loopreturns and
DebouncedChan
returns to its initial state.