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

throttleTime(n, undefined, {leading: true, trailing: true}) ... double output #2727

Closed
sod opened this issue Jul 6, 2017 · 7 comments · Fixed by #5687
Closed

throttleTime(n, undefined, {leading: true, trailing: true}) ... double output #2727

sod opened this issue Jul 6, 2017 · 7 comments · Fixed by #5687

Comments

@sod
Copy link

sod commented Jul 6, 2017

RxJS version: 6.5.1
Code to reproduce (6.5.1): https://stackblitz.com/edit/rxjs-tthiju
Expected behavior: One value initially, then defer next value for given duration
Actual behavior: One value initially, two values each duration
Additional information:

Test:

import { interval } from 'rxjs'; 
import { throttleTime, take } from 'rxjs/operators';

interval(50).pipe(
  throttleTime(1234, undefined, {leading: true, trailing: true}),
  take(8),
).subscribe(x => console.log(x));

// actual output: 0----24-25----49-50----74-75----99|
// expected output: 0----24----49----74----99----124----149----174|
@jscti
Copy link

jscti commented Mar 13, 2018

Has anybody found a work around on this ?

@tim-kuteev
Copy link

Hi jscti,

I think the work around for that might be to to give up on leading value.

.throttleTime(1234, undefined, {leading: false, trailing: true})

Note that in this case you will be missing the first value. And there is also opened issue for single value #2859.

MatthiasKunnen added a commit to MatthiasKunnen/rxjs that referenced this issue Apr 23, 2019
Fix an issue with throttleTime emitting both leading and trailing values in the same time window.

Double emission problem:
source:   a123b12-c-23d-2-ef---
expected: a---b---c---d---e---f
actual:   a---b1---c2---2-e---f

Closes ReactiveX#2466 and ReactiveX#2727.
Follows ReactiveX#2749 and ReactiveX#2864.

BREAKING CHANGE: throttleTime no longer emits both leading and trailing
values in the same time window.
@simeyla
Copy link

simeyla commented Jun 17, 2019

Would distinctUntilChanged() work after throttleTime - at least for some situations?

@ubugnu
Copy link

ubugnu commented Jun 17, 2019

Would distinctUntilChanged() work after throttleTime - at least for some situations?

Yes it would work, for example:

distinctUntilChanged((prev, curr) => curr - prev < minWaitTime/1000)

@sod
Copy link
Author

sod commented Jun 17, 2019

Well, let me try to propose a fix again via #4864 :D

MatthiasKunnen added a commit to MatthiasKunnen/rxjs that referenced this issue Jul 24, 2019
Fix an issue with throttleTime emitting both leading and trailing values in the same time window.

Double emission problem:
source:   a123b12-c-23d-2-ef---
expected: a---b---c---d---e---f
actual:   a---b1---c2---2-e---f

Closes ReactiveX#2466 and ReactiveX#2727.
Follows ReactiveX#2749 and ReactiveX#2864.

BREAKING CHANGE: throttleTime no longer emits both leading and trailing
values in the same time window.
@adolgoff
Copy link

adolgoff commented Mar 6, 2020

Are there any plans to merge it?

benlesh added a commit to benlesh/rxjs that referenced this issue Sep 2, 2020
…least the throttled amount

Works to align the behavior with expectations set by lodash's throttle

- Updates tests
- Ensures trailing throttle will wait to notify and then complete
- Ensures that every time we emit a value a new throttle period starts

fixes ReactiveX#3712
related ReactiveX#4864
fixes ReactiveX#2727
closes ReactiveX#4727
related ReactiveX#4429
benlesh added a commit to benlesh/rxjs that referenced this issue Sep 3, 2020
…least the throttled amount

Works to align the behavior with expectations set by lodash's throttle

- Updates tests
- Ensures trailing throttle will wait to notify and then complete
- Ensures that every time we emit a value a new throttle period starts

fixes ReactiveX#3712
related ReactiveX#4864
fixes ReactiveX#2727
closes ReactiveX#4727
related ReactiveX#4429
benlesh added a commit that referenced this issue Sep 3, 2020
…least the throttled amount (#5687)

* fix(throttleTime): ensure the spacing between throttles is always at least the throttled amount

Works to align the behavior with expectations set by lodash's throttle

- Updates tests
- Ensures trailing throttle will wait to notify and then complete
- Ensures that every time we emit a value a new throttle period starts

fixes #3712
related #4864
fixes #2727
closes #4727
related #4429

* chore: Address comments and add comments to the code
@sod
Copy link
Author

sod commented Sep 3, 2020

Oh nice, thank you for fixing it ben 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment