Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is Observable#asObservable() in RxJava2?

Tags:

java

reactivex

I would like to observe my BehaviourSubject. In RxJava 1 I was calling asObservable(), which is now gone.

I found publish() but it returns connectable, which I don't want to.

How to turn behavior subject into observable in RxJava 2?

like image 353
Dims Avatar asked Mar 21 '17 14:03

Dims


People also ask

Where are observables used?

Observables provide support for passing messages between parts of your application. They are used frequently in Angular and are a technique for event handling, asynchronous programming, and handling multiple values.

Where is observable used in Angular?

Angular makes use of observables as an interface to handle a variety of common asynchronous operations. For example: The HTTP module uses observables to handle AJAX requests and responses. The Router and Forms modules use observables to listen for and respond to user-input events.

What is observable example?

An observable is a function that creates an observer and attaches it to the source where values are expected from, for example, clicks, mouse events from a dom element or an Http request, etc.

How do you explain observable?

capable of being or liable to be observed; noticeable; visible; discernible: an observable change in attitude. worthy or important enough to be celebrated, followed, or observed: an observable holiday. deserving of attention; noteworthy.


2 Answers

You're probably looking for Observable.hide()

Hides the identity of this Observable and its Disposable. Allows hiding extra features such as Subject's Observer methods or preventing certain identity-based optimizations (fusion).

like image 103
Kiskae Avatar answered Sep 29 '22 05:09

Kiskae


From the What's different in 2.0 page, from 1.x Observable to 2.x Flowable :

asObservable : renamed to hide(), hides all identities now

So it seems that the hide method is what you are looking for.

like image 35
Arnaud Avatar answered Sep 29 '22 05:09

Arnaud