Skip to content
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

Remove RACAsyncSubject in favor of RACReplaySubject #87

Closed
jspahrsummers opened this issue Oct 17, 2012 · 7 comments
Closed

Remove RACAsyncSubject in favor of RACReplaySubject #87

jspahrsummers opened this issue Oct 17, 2012 · 7 comments
Assignees

Comments

@jspahrsummers
Copy link
Member

It's not clear what advantage RACAsyncSubject offers over RACReplaySubject. It seems like the latter has a strict superset of the former's behavior. It also seems like a safer default to replay the whole subscribable stream, rather than just the last thing sent.

@joshaber
Copy link
Member

Yeah I've wondered about this before...

Note that RACAsyncSubject does behave slightly differently. It only sends the next when it completes, whereas RACReplaySubject sends them as it gets them.

I think the real value is the semantic difference between the two. RACAsyncSubject says you're sending a single value. It's a promise or a future or whatever. Point being it's just one thing. RACReplaySubject says you want to catch up anyone that missed anything, but still act like a stream. I think that difference communicated by different types is valuable.

I'd be interested in getting @xpaulbettsx's thoughts on this.

@anaisbetts
Copy link

So, the only difference between them that should be there is that AsyncSubject doesn't replay non-last items - with both of them, until it completes (i.e. when it's still "live"), they both just act like a normal Subject. If you got rid of AsyncSubject it probably would be fine. On .NET, AsyncSubject has some additional secret-sauce to support the await keyword, so it makes more sense that it is a separate class.

@jspahrsummers
Copy link
Member Author

@joshaber The typical use case for RACAsyncSubject seems to be network operations, which I think are absolutely better modeled as a stream, and not as a future.

I think the problem is that RACAsyncSubject is somewhat fragile. If you send more than one value, suddenly the behavior of any subscribers becomes a lot less deterministic. I can't think of a case where I wouldn't want a RACReplaySubject instead.

I think that difference communicated by different types is valuable.

It's worth noting that interfaces typically shouldn't expose whether a RACAsyncSubject or RACReplaySubject is being returned. Callers should just see a RACSubscribable, and how it handles asynchronous behavior is either described in documentation, or an implementation detail.

@joshaber
Copy link
Member

Yeah good point 👍

@joshaber
Copy link
Member

FWIW, I'm going to do a pass through soon to do some housekeeping. I can remove RACAsyncSubject and RACBehaviorSubject when I do that.

@jspahrsummers
Copy link
Member Author

🤘 Sounds good, though we should keep in mind that RACAsyncSubject got some important concurrency fixes which RACReplaySubject might not have.

@joshaber
Copy link
Member

✨ 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants