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

Different behavior of takeUntil in RxJS 5 and 6 #3727

Closed
d3lm opened this issue May 22, 2018 · 2 comments
Closed

Different behavior of takeUntil in RxJS 5 and 6 #3727

d3lm opened this issue May 22, 2018 · 2 comments

Comments

@d3lm
Copy link

d3lm commented May 22, 2018

RxJS version: 6.2.0

Code to reproduce:

import { from, interval, of } from 'rxjs';
import { share, filter, takeUntil, tap } from 'rxjs/operators';

const rules = [true, true, true];

const results$ = from(rules).pipe(
  share()
);

const fails$ = results$.pipe(
  filter(value => !value),
  tap(value => console.log('FAIL'))
);

results$.pipe(
  takeUntil(fails$)
).subscribe(value => console.log('SUBSCRIBE', value));

Expected behavior: There are a two core streams involved in the code above, results$ and fails$. fails$ is based off of results$ and filters out all truthy source values, meaning it only emits falsy values. results$ should now emit values until fails$ produces a value. So when results$ synchronously emits 3 values [true, true, true], fails$ should never emit and it doesn't because of the filter operator. Hence the observer passed to subscribe should be called 3 times.

Actual behavior:

The next callback should be called 3 times. However, no values are propagated via the observer passed to results$.subscribe(...). When takeUntil is removed, everything works as expected. Even if I leave takeUntil in and only change the notifier to something like interval(1000), it works as expected.

Here's a StackBlitz that demonstrates the issue.

It somehow makes sense in this situation as everything is happning synchronously. This means that takeUntil creates a subscription to fails$, which then subscribes to results$. The thing is that results$ emits synchronously when takeUntil subscibres and it completes so the outer subscription on results$ will never receive any values. This is just a guess and my shot at explaining this behavior. The weird thing is that it works when using RxJS 5.5.11. Is this some edge case that was "fixed" in RxJS 6 or which one is incorrect?

Here's a runnable demo on StackBlitz.

We have noticed the issue while upgrading MachineLabs to RxJS 6.x. Here's the corresponding PR. Due to failing tests we were able to spot a different behavior, so we started to investigate.

@benlesh
Copy link
Member

benlesh commented May 22, 2018

I think the fix to keep sources from being subscribed to if the notifier synchronously emits is what you're setting here: #3504

Yes, this is expected behavior.

Thank you for the detailed issue, @d3lm .. it's appreciated.

@benlesh benlesh closed this as completed May 22, 2018
@d3lm
Copy link
Author

d3lm commented May 22, 2018

Thanks for replying to this issue and pointing me to the corresponding PR.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants