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

Throttle with timeout is producing infinite stack traces #4963

Open
mikila85 opened this issue Aug 12, 2019 · 5 comments
Open

Throttle with timeout is producing infinite stack traces #4963

mikila85 opened this issue Aug 12, 2019 · 5 comments

Comments

@mikila85
Copy link

mikila85 commented Aug 12, 2019

Bug Report

Current Behavior

Throttle with interval (not throttleTime becuase I need leading & trailing) is creating a very long stack trace of repeated setInterval:

image

Reproduction
no reproduction, need to debug stack trace.

this.updateSubject.pipe(throttle(() => interval(5000), {
            leading: true,
            trailing: true
        })).subscribe(() => this.doAction());

Expected behavior
should not create larger and larger stack traces

Environment

  • Runtime: Chrome latest
  • RxJS version: 6.3.3
@cartant
Copy link
Collaborator

cartant commented Aug 13, 2019

You probably want to use timer instead of interval - the former will emit only once, whereas the latter will emit repeatedly.

@mikila85
Copy link
Author

mikila85 commented Sep 2, 2019

but i want it to happen every 5000 miliseconds, repeatedly..

@cartant
Copy link
Collaborator

cartant commented Sep 3, 2019

From the docs:

Emits a value from the source Observable, then ignores subsequent source values for a duration determined by another Observable, then repeats this process.

Where 'another Observable' is the the observable you return from the function passed to throttle. Note that the function is called multiple times; it's called each time a value is emitted from the throttled observable - that's what's implied by 'repeats this process'.

It's possible that there is a bug with the implementation of throttle and it's expecting notifier observables to emit only a single value, but, regardless of that, IMO you should not be passing a notifier that emits more that once, as the notifiers are used only to determine when the next source value is supposed to be emitted. Once emitted, a new notifier is created.

@mikila85
Copy link
Author

mikila85 commented Sep 6, 2019

You are right, timer is the one I should have used, thank you for pointing it out to me!
Still when combined with leading and trailing I see stack trace getting longer and longer :(

@cartant
Copy link
Collaborator

cartant commented Sep 6, 2019

Yeah, I suspect this is actually a bug. It should not matter whether or not the notifier emits multiple times - the throttle implementation should unsubscribe upon the first notification - but, unfortunately, that does not appear to be happening. I will have a look at this sometime - so please leave this open - but, in general I'd suggest that it's best to ensure any notifier emits only once.

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

No branches or pull requests

2 participants