-
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
Synchronous emit to switchMap
during the processing of previous emit prevents the first from unsubscribing
#7455
Comments
This tricked me for a few minutes. This isn't a bug, it's expected behavior.
What you're looking for is |
Hi @benlesh thanks for the response. I think I'm a bit confused or not totally following the explanation. I do expect the |
const sub = new Subject<number>();
const finalizations = new Subject<number>();
sub
.pipe(
switchMap((id) => {
return from(Promise.resolve(id)).pipe(
finalize(() => {
console.log(`finalize for ${id}`);
finalizations.next(id);
})
);
})
)
.subscribe((id) => {
console.log(`next emit for ${id}`);
});
finalizations.pipe(filter((id) => id === 1)).subscribe(() => {
sub.next(3);
});
sub.next(1);
sub.next(2);
|
Moral of the story: Don't do too much synchronous stuff in observables, it's really weird. :P |
Describe the bug
I think this may be a duplicate of #7230 but not entirely sure.
When a
switchMap
is in the process of subscribing to onenext
notification, it will not unsubscribe if anothernext
happens synchronously.Expected behavior
switchMap
should always unsubscribe from previous subscriptions if a new value comes in.Reproduction code
https://stackblitz.com/edit/rxjs-a21xi5?devtoolsheight=60&file=index.ts
This outputs the following
I would expect it to not produce "next emit for 2"
Reproduction URL
No response
Version
8.0.0-aplha-12
Environment
No response
Additional context
This is not a regression. I'm seeing this as far back as rxjs 6.
The text was updated successfully, but these errors were encountered: