-
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
Unexpected behaviour of first operator together with switchMap #2455
Comments
This sounds like a bug in |
@trxcllnt In a way it is The problem is since every operator is implemented via This is exactly what You can see it here: https://github.com/ReactiveX/rxjs/blob/master/src/operator/switchMap.ts#L113 My point is - should an operator have power to intercept unsubscription logic of source observable? When observable sends complete or error notification, shouldn't one central mechanism make sure that it is always unsubscribed, so that operators are not prone to such mistakes? |
As far as I understand, in tc39 spec, if I call |
In other words: shouldn't this: https://github.com/ReactiveX/rxjs/blob/master/spec/operators/switchMap-spec.ts#L57-L58 be absolutely illegal? We have source that completed, but we are still subscribing to it for some time. |
@Podlas29 ah, yes there is a deeper issue here. I'll comment on #2457 in more detail. |
This one is interesting. I'm actually curious if the subscription tests have a flaw or if it's the actual implementations of the operators (where they override various parts of Subscriber, perhaps they're not properly calling unsubscribe in a few places anymore) |
I think the same problem is with the
I'd expect this example not to print anything because I triggered the notification Observable in See demo: https://jsbin.com/wimebel/3/edit?js,console This can be easily fixed by switching the order of |
#2463) Force unsubscription logic when operator completes or errors, so that source Observable is only subscribed as long as it has to, even when combined with operators that do not immediately unsubscribe from 'first' when it completes or errors. Closes #2455 BREAKING CHANGE: unsubscription cadence has changed for `first`, this means side-effects related to unsubscription may occur at a different time than in previous versions.
#2463) Force unsubscription logic when operator completes or errors, so that source Observable is only subscribed as long as it has to, even when combined with operators that do not immediately unsubscribe from 'first' when it completes or errors. Closes #2455 BREAKING CHANGE: unsubscription cadence has changed for `first`, this means side-effects related to unsubscription may occur at a different time than in previous versions.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
RxJS version: 5.2.0
Code to reproduce:
var x = Rx.Observable.interval(1000)
.do( x=> console.log("One"))
.first()
.switchMap(x => Rx.Observable.interval(1000))
.do( x=> console.log("Two"))
.subscribe((x) => {})
Expected behaviour:
// In console you will see:
// One
// Two
// Two
// Two
// Two
// etc...
Actual behaviour:
// In console you will see:
// One
// One
// Two
// One
// Two
// One
// etc...
Additional information:
I've expected that first() in this case should behave exactly the same as a take(1) but behaviour is quite different
The text was updated successfully, but these errors were encountered: