-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
Should flatMap restart the inner observable if it's re-emitted? #55
Comments
If the returned What would happen in the following case, for example? parentObservable1.flatMap(parentEvent => makeChildObservable(parentEvent))
parentObservable2.flatMap(parentEvent => makeChildObservable(parentEvent)) I've never done this, so I don't really case about this particular case :), but I suppose changing the behavior to not restart it will make it make somewhat more sense. Unless someone has a really good use case for the opposite. |
To clarify, when I said "stopped" and "restarted", I meant assuming there are no other observers of That's actually a very good point. |
Consider the following code for both
SwitchStreamStrategy
andSwitchSignalStrategy
:parentObservable.flatMap(parentEvent => makeChildObservable(parentEvent))
if
parentObservable
emits1
then2
, andmakeChildObservable(parentEvent)
returns the exact samechildObservable
both times, thatchildObservable
will be stopped and then started again when the parent emits2
.I'm inclined to change the behaviour so that
childObservable
is not restarted in this case, so that it just continues running, but I'm not sure. Some streams have side effects when they start (such as the new AjaxEventStream), so while this should be a rare issue, it's not just a minor performance concern, but a potentially breaking behaviour change.My thinking is that if the reference to
childObservable
is exactly the same in both cases, the user likely intended to cache it for some reason, probably to avoid recreating / restarting it.The main question is, what do users expect to happen in this case? Do you expect nothing to happen when switching from
childObservable
to the exact samechildObservable
(same reference, not just==
), or do you expect it to be stopped and immediately started again? Do you have code that would be affected by this?I could make this configurable if there is demand for that, but I still need to figure out which default would make the most sense.
The text was updated successfully, but these errors were encountered: