-
Notifications
You must be signed in to change notification settings - Fork 3k
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
7.0 bug, second switchMap gets executed hundreds of time initially #6167
Comments
I've narrowed down the issue. It's a problem with For instance, the following snipped works perfectly fine (because the source is async): import { Observable } from "rxjs";
import { shareReplay } from "rxjs/operators";
const source$ = new Observable(subscriber => {
const token = setTimeout(() => {
subscriber.next(Math.random());
subscriber.complete();
}, 0);
return () => {
clearTimeout(token);
};
});
const randomNumber$ = source$.pipe(shareReplay(1));
randomNumber$.subscribe(x => {
console.log(x);
randomNumber$.subscribe(x => {
console.log(x);
});
}); However, this would likely hang your browser: import { Observable } from "rxjs";
import { shareReplay } from "rxjs/operators";
const source$ = new Observable(subscriber => {
subscriber.next(Math.random());
subscriber.complete();
});
const randomNumber$ = source$.pipe(shareReplay(1));
randomNumber$.subscribe(x => {
console.log(x);
randomNumber$.subscribe(x => {
console.log(x);
});
}); And this also works fine (because the second subscription gets created after complete): import { Observable } from "rxjs";
import { shareReplay } from "rxjs/operators";
const source$ = new Observable(subscriber => {
subscriber.next(Math.random());
subscriber.complete();
});
const randomNumber$ = source$.pipe(shareReplay(1));
randomNumber$.subscribe({
next: x => {
console.log(x);
},
complete: () => {
randomNumber$.subscribe(x => console.log(x));
}
}); |
Closing as a (far-from-obvious) dupe of #6144. |
Bug Report
The code:
Link to demo
Current Behavior
I expect to see one log of a random number between 0 and 19.
Expected behavior
I see hundreds of logs those random numbers.
The text was updated successfully, but these errors were encountered: