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

Debounce drops last emitted value if complete emitted too soon #257

Closed
CarlLeth opened this issue Jun 27, 2018 · 1 comment · Fixed by #259
Closed

Debounce drops last emitted value if complete emitted too soon #257

CarlLeth opened this issue Jun 27, 2018 · 1 comment · Fixed by #259

Comments

@CarlLeth
Copy link

Given this stream:
const stream = fromDiagram('-1----2-|').debounce(50),
1 will be emitted, but not 2, because debounce._c calls this.clearInterval() immediately even if a value is waiting to be emitted.

Debounce drops values with the understanding that a fresher value is coming soon after, but that assumption is violated by dropping the last value. If debounce's purpose is to wait until a rapidly-changing value has settled down, I propose that when it receives complete, things have obviously settled down and it should emit any pending value immediately and then complete.

I am using debounce to prevent the problem where xs.combine(a, b, c, d) emits three (potentially erroneous) intermediate values if a, b, c, and d all change from the same initial event. xs.combine(a,b,c,d).debounce(0) should fix the problem nicely, but it doesn't, because of the aforementioned issue. Another option would be to change combine and merge so that synchronous values from multiple of their inputs only trigger one output emission.

@staltz
Copy link
Owner

staltz commented Jul 3, 2018

[upon source completion] it should emit any pending value immediately and then complete.

I agree this is the right behavior for debounce and we should fix it through a PR. Thanks for reporting @CarlLeth

xtianjohns added a commit to xtianjohns/xstream that referenced this issue Jul 18, 2018
Emit any pending value, then complete, if a source stream completes
before a debounce interval closes.

Resolve staltz#257.
xtianjohns added a commit to xtianjohns/xstream that referenced this issue Jul 18, 2018
Emit any pending value, then complete, if a source stream completes
before a debounce interval closes.

Resolve staltz#257.
xtianjohns added a commit to xtianjohns/xstream that referenced this issue Jul 18, 2018
Clear pending value upon completion. Support falsy emission values such
as `false` and 0.

Related to staltz#257.
staltz pushed a commit that referenced this issue Jul 22, 2018
Emit any pending value, then complete, if a source stream completes
before a debounce interval closes.

Resolve #257.
staltz pushed a commit that referenced this issue Jul 22, 2018
Clear pending value upon completion. Support falsy emission values such
as `false` and 0.

Related to #257.
staltz pushed a commit that referenced this issue Jul 22, 2018
Emit any pending value, then complete, if a source stream completes
before a debounce interval closes. Clear pending value upon
completion. Support falsy emission values such as `false` and 0.

Resolve #257.
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 a pull request may close this issue.

2 participants