question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Debounce repeats last emission at completion

See original GitHub issue

Debounce operator emits last value at completion, even though no event is delayed.

This is apparently due to the timer not being reset after firing: https://github.com/cujojs/most/blob/a88c3169d231bcfe6f780cbd1db94b3b304ff284/src/combinator/limit.js#L92

On call to end, this is interpreted as a pending event.

Expected result

Once a debounced event has fired, it should not fire on stream completion.

Actual Result

See codepen: https://codepen.io/corolla/pen/XVwGQY?editors=1012#0

Notice ‘foo’ outputted twice indicating emission on stream completion.

Versions

  • most.js: 1.7.2
  • Chrome 63

Steps to reproduce

Run code, observe foo emitting twice.

Code to reproduce

most
  .never()
  .startWith('foo')
  .until(most.of().delay(1000))
  .debounce(100)
  .subscribe({
    next: console.log,
    complete: () => console.log('complete')
});

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
briancavaliercommented, Feb 1, 2018

@rhartvig Cool, glad that works for you 👍

Yeah, I debated something similar, too. I’ll try to explain why I went with the current approach. The value stored in DebounceSink is mutable, and tracks the latest seen value, and the one stored in DebounceTask is immutable and represents the pending debounce value. The use case of the former is only for end, and the use case for the latter is to implement the actual debounce functionality. Those are subtly different intents, and I thought keeping them separate might be better.

That said, I think your idea is interesting. I hadn’t considered invoking the task manually. I’ll give it a bit more thought today.

In the meantime, I think we’ll release this as is, to get the bug fix out. If we decided to change the implementation, we can do that in another release.

0reactions
briancavaliercommented, Feb 2, 2018

Wouldn’t that happen as part of run() -> _event() -> _clearTimer() => timer.dispose() ?

Aha! Yes, you’re right. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

take() with debounceTime() takes the last element only
debounceTime will then wait 1000ms after the last emission is received and emit it. The order of your operators within the pipe matters....
Read more >
Debouncing and Throttling Explained Through Examples
Debounce and throttle are two similar (but different!) techniques to control how many times we allow a function to be executed over time. ......
Read more >
Drop and Delay Observable Emissions with RxJS debounce
While Delay time shifts each emission by one second, debounce waits for one second of silence, and then it emits the most recent...
Read more >
Master RxJs: Debounce all but first | by Lars Holdaas - Medium
This inner Observable then completes, as take(1) forces completion after a single emission has passed through, and our subscription switches ...
Read more >
RxJS debounce vs throttle vs audit vs sample — Difference ...
It can be set to emit the first and/or the last value in the given time window. Then it repeats this procedure.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found