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

bug(throttle): Does not emit last value on source complete #5732

Open
benlesh opened this issue Sep 15, 2020 · 5 comments
Open

bug(throttle): Does not emit last value on source complete #5732

benlesh opened this issue Sep 15, 2020 · 5 comments
Labels
bug Confirmed bug

Comments

@benlesh
Copy link
Member

benlesh commented Sep 15, 2020

throttleTime(n, s, config) should be equivalent to throttle(() => timer(n, s), config)... But it's not. The issue is that throttle does not behave correctly when the source completes.

If the source completes, we're trailing, and we have a trailing value already, the result should wait for the throttle duration to end, then emit the last value, then complete the result. If the source completes and we don't have a trailing value -- or we're not trailing -- the result should complete.

@benlesh benlesh added the bug Confirmed bug label Sep 15, 2020
@alexsherekin
Copy link
Contributor

I would like to work on this issue. It looks like a good first task to contribute to RxJS.

@alexsherekin
Copy link
Contributor

After the refactoring the initial bug is fixed. I created a PR with additional tests.

@OliverJAsh
Copy link
Contributor

OliverJAsh commented Feb 15, 2021

Until v7 is released, I'm using this workaround:

/**
 * Workaround for https://github.com/ReactiveX/rxjs/issues/5732
 * Fixed in v7
 */
export const throttleWithFix: typeof RxJSOperators.throttle = (...params) => (ob$) =>
  ob$.pipe(
    RxJSOperators.publish((published$) => {
      const last$ = pipe(published$, RxJSOperators.last());
      const throttled$ = pipe(published$, RxJSOperators.throttle(...params));
      return RxJS.merge(throttled$, last$);
    }),
  );

@akaltar
Copy link

akaltar commented Feb 28, 2021

Is there an option to fix this for a 6.6.7 release?
I'd be happy to try and backport the fix and test from the v7 alpha.

@gewoonwoutje
Copy link

Closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug
Projects
None yet
Development

No branches or pull requests

5 participants