-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Change share(replay:scope:)
's default scope to .forever
#1527
Conversation
Hi @inamiy , This is an official change, please take a look at CHANGELOG.md (4.0.0-beta.1):
There were also PRs that announced those changes. Share replay only makes sense when one has non terminating observable sequence and its main use case is optimization. e.g.:
Another motivation is that The reason why we've had I was thrilled to find that out because I've considered that original There are multiple problems of using
I would say that there might be a couple of edge use cases that might justify its usage, but these are really edge cases IMHO. Using any type of |
@kzaher I personally think
I wasn't aware of this. Do you have a reference? |
You can't use
You can check out source code and create some test examples. |
Yes, I know I'm not still sure about other ReactiveX implementation, but if One possible approach would be: public func share() {
return share(replay: 0, scope: .forever) // same as `publish().refCount()`
}
public func share(replay: Int /* no default value */, scope: SubjectLifetimeScope = .whileConnected) {
...
} Or, if we don't really need to care about other platforms too much, keeping the current implementation is good enough. |
Ref: RxJS doesn't seem to have |
It doesn't matter if n = 0 because error caching is also important. If operator caches error forever, retry operator won't work as expected, and yes, this is extremely important property. e.g. Websockets.
I'm not sure what do you mean by this. We are consistent with all of them. They have exactly the same behavior when you don't explicitly specify sharing strategy and just write
There are different Rx implementations out there that have different behavior regarding this. Two major groups of behaviors are:
Rx.NET -> forever I think that whileConnected is sensible default value, but user always has a choice which behavior to adopt.
If you are implying that it doesn't have that enum in public interface, that is correct. It only supports .whileConnected behavior and javascript doesn't even have a concept of enums (although you can model them if you like). Or did you refer to something else? |
So, the main goal here is really "retry" availability, which means "share while connected and retryable after all disconnected or received error/completed", right? But you are definitely right that ReactiveX itself now has So anyway... Since you've already digged into other platform and confirmed the new behavior, I'm now 👍 to And I think #1527 (comment) will be useful info to attach to the documentation. I can now close this PR. Thanks for discussion, @kzaher :) |
That's one part of problem that is solves. The other one is stale cache of sequence elements.
IMHO hot and cold is simply a fairy tale that I often see being mentioned on twitter in cases when:
If somebody asks you what about hot and cold, try to perform this experiment. Ask them, "Is web socket hot or cold"?
First milestone should be easily achieved.
Then ask them: "Is event hot or cold?":
Then ask them "is result hot or cold":
So here we are:
at least one of And now the final part. Well isn't websocket equivalent to:
How can websocket API be both hot and cold, isn't this a contradiction?
I'm assuming Google will index it somehow but yes, it would be nice to improve the docs. We are open for PRs. |
Hi @kzaher ,
There is an issue in
share(replay:scope:)
that uses.whileConnected
as a default value.When calling
.share()
without any arguments, this will no longer behave as previous.publish().refCount()
in v3.6.1, but will work quite differently as follows, especially when upstream is finite cold observable:Replacing above with
.share(scope: .forever)
will work as expected (same as.share()
in v3.6.1):Since
.share()
as.publish().refCount()
is the right implementation for ReactiveX, I think it is better to have.forever
as a default scope instead.