-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Creating Observable#create overloads for SyncOnSubscribe and AsyncOnSubscribe #3738
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
Conversation
I like this addition. It makes it far more discoverable to do 'create' in a safer way. +1 |
I'm worried that having the same name will cause method resolution problems with other not so strict JVM languages. |
Looks good. @abersnaze what's an example? |
* @see <a href="http://reactivex.io/documentation/operators/create.html">ReactiveX operators documentation: Create</a> | ||
*/ | ||
public static <S, T> Observable<T> create(SyncOnSubscribe<S, T> syncOnSubscribe) { | ||
return new Observable<T>(hook.onCreate(syncOnSubscribe)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you couldn't call create(OnSubscribe)
because of overload problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can still call to the OnSubscribe
overload and it would work just fine. The purpose behind the 2 new overloads is discoverability.
Sure these two methods point to the classes, but I'd prefer those |
@akarnokd so you would prefer to have the static create methods explicitly listed out? This is how that would look when in an IDE (i.e. in Eclipse with One static method per concrete option: create(OnSubscribe<T> f)
createAsyncSingleState(Func0<? extends S> generator, Action3<? super S, Long, ? super Observer<Observable<? extends T>>> next)
createAsyncSingleState(Func0<? extends S> generator, Action3<? super S, Long, ? super Observer<Observable<? extends T>>> next, final Action1<? super S> onUnsubscribe)
createAsyncStateful(Func0<? extends S> generator, Func3<? super S, Long, ? super Observer<Observable<? extends T>>, ? extends S> next, Action1<? super S> onUnsubscribe)
createAsyncStateless(Action2<Long, ? super Observer<Observable<? extends T>>> next)
createAsyncStateless(Action2<Long, ? super Observer<Observable<? extends T>>> next, Action0 onUnsubscribe)
createSyncSingleState(Func0<? extends S> generator, Action2<? super S, ? super Observer<? super T>> next)
createSyncSingleState(Func0<? extends S> generator, Action2<? super S, ? super Observer<? super T>> next, Action1<? super S> onUnsubscribe)
createSyncStateful(Func0<? extends S> generator, Func2<? super S, ? super Observer<? super T>, ? extends S> next, Action1<? super S> onUnsubscribe)
createSyncStateful(Func0<? extends S> generator, Func2<? super S, ? super Observer<? super T>, ? extends S> next)
createSyncStateless(Action1<? super Observer<? super T>> next)
createSyncStateless(Action1<? super Observer<? super T>> next, Action0 onUnsubscribe) One overload per highlevel category (Sync, Async) create(OnSubscribe<T> f)
create(SyncOnSubscribe<S, T> syncOnSubscribe)
create(AsyncOnSubscribe<S, T> asyncOnSubscribe) This isn't exactly a direct apples-to-apples representation as you'd have to use the create(SyncOnSubscribe.createStateless(Action1<? super Observer<? super T>> next)) I think I prefer the latter because the surface area of the Observable is constrained to two (three-ish) high level categories of creation options. |
31b87a0
to
e2709f0
Compare
I've added more explanation to the javadoc. |
I prefer current version (with overload per high-level category). |
e2709f0
to
479d1e0
Compare
The test seems to be a flaky unit test.
I have added |
Travis sometimes seems to slow down drastically; that 1 second wait in that test is like 1000x more than usually needed to verify the behavior. Just rerun the test in this case. We can start with your two methods and add the rest later. |
I would prefer not to have both styles personally as redundancy makes for a cluttered and confusing api. Is it a personal preference for listing all variants? |
Only the sync ones, the async ones can be hidden behind that create overload. |
I'm fine discussing that when the time comes. |
Creating Observable#create overloads for SyncOnSubscribe and AsyncOnSubscribe
@davidmoten I can't remember the exact instances of the issue but I'm not as familiar with scala, clojure, groovy, or kotlin. I did a simple test in groovy, that worked, just because I had a REPL handy. it would be nice have a lowest common denominator for method signatures so we don't make it unnecessarily difficult in any of those languages. |
Kotlin handles the overloads fine 👍 On Thu, Mar 3, 2016 at 7:26 PM George Campbell [email protected]
|
This is to facilitate the discovery of methods for creating observables that respect back pressure semantics. Currently the
Observable#create(OnSubscribe)
static method is the easiest method to discover for creating an observable which does not provide clear facilities for managing back pressure.