Reputation: 2388
I understand that usage of Observable.create
is discouraged in RxJava due to lack of backpressure support. Due to this, I've taken to using the new Observable.fromAsync
to wrap callback API's, as it handles backpressure with otherwise seemingly the same behaviour as Observable.create
.
However in these draft docs, the suggestion seems to be that exposing my created observable like below should solve this issue:
Observable<T> observable = Observable.create(onSubscribe).onBackpressureBuffer();
Is this correct? At this point what is the difference between the two operators? If this isn't correct, is there ever any justification to use .create
over .fromAsync
?
Upvotes: 4
Views: 2222
Reputation: 70007
create
was mostly there to support the internal workings of RxJava and for those who know how to implement operators. It requires one to handle backpressure and unsubscription manually because different operators require different approaches to them.
fromEmitter
makes the backpressure requirement explicit and offers some unsubscription management as well. Therefore, it is harder to misuse it. We recommend switching to it if one needs something to wrap a classical callback API.
Edit: as of RxJava 1.2.6 the method name is fromEmitter
.
Upvotes: 5