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

debounceTime emit right away when they reach the end of the observable they are debouncing #4660

Open
shenlin192 opened this issue Mar 24, 2019 · 5 comments
Labels
docs Issues and PRs related to documentation

Comments

@shenlin192
Copy link

Bug Report

Current Behavior
debounce and debounceTime emit right away when they reach the end of the observable they are debouncing as described in https://stackoverflow.com/a/55248103/5692151. This behavior is not described in the doc https://rxjs-dev.firebaseapp.com/api/operators/debounceTime

Reproduction

Expected behavior
If I understand correctly what the doc says, the observable should be emiited after a duration dueTime but not immediately.

Environment

  • Runtime: Chrome 72
  • RxJS version: Rxjs 6.2.1
@cartant
Copy link
Collaborator

cartant commented Mar 25, 2019

IMO, this isn't a bug and is reasonable behaviour. The point of denouncing is to ensure notifications are not emitted too quickly. If the source completes, there will be no further notifications, so emitting the last notification right away is justifiable. I see no reason to wait out the delay.

@shenlin192
Copy link
Author

Hello @cartant
If so, won't it be nice to mention such behavior in the doc? :) It's not really obvious.

@cartant
Copy link
Collaborator

cartant commented Mar 25, 2019

Yeah, if it's the expected behaviour, it should be mentioned in the docs.

Also, I guess it could be argued that it should be delayed in some circumstances. If the source emits a value shortly after an already-debounced value has been emitted from the operator, there are situations in which the subscriber could receive two notifications that are separated by an interval less than the specified duration.

@niklas-wortmann niklas-wortmann added the docs Issues and PRs related to documentation label Mar 28, 2019
@infacto
Copy link

infacto commented Apr 8, 2021

image

This is counting and counting and counting ... never ends. Like interval(1000). Why? I checked the ngAfterViewChecked method. It stops after a few times. But when I use debounceTime (or another similar pipe) the log does not stop. Event with BehaviorSubject.

If this is by intended, what should I use to trigger only once after the specified time and end of emission?

@ivan-kleshnin
Copy link

ivan-kleshnin commented May 12, 2023

IMO, this isn't a bug and is reasonable behaviour. The point of denouncing is to ensure notifications are not emitted too quickly. If the source completes, there will be no further notifications, so emitting the last notification right away is justifiable. I see no reason to wait out the delay.

Ok, but it's hard to justify why throttleTime behaves in the opposite way. It does delay a single value in trailing mode:

timer(2000)
  .pipe(
    RX.throttleTime(5000, undefined, {leading: false, trailing: true})
  )
  .subscribe(console.log) // single event after 7 seconds

vs

timer(2000)
  .pipe(
    RX.debounceTime(5000) // no leading/trailing config, docs describe trailing behavior
  )
  .subscribe(console.log) // single event after 2 seconds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Issues and PRs related to documentation
Projects
None yet
Development

No branches or pull requests

5 participants