Java Code Examples for io.reactivex.Observable.fromPublisher()

The following are Jave code examples for showing how to use fromPublisher() of the io.reactivex.Observable class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: AndroidToolbox   File: Utils.java   Source Code and License Vote up 5 votes
/**
 * Converts DataBinding's ObservableField  to RxJava2's Observable
 * see https://habrahabr.ru/post/328512/
 * @param observableField
 * @param <T>
 * @return Observable (RxJava2)
 */
public static <T> Observable<T> toObservable(@NonNull final ObservableField<T> observableField) {

    return Observable.fromPublisher(asyncEmitter -> {
        final android.databinding.Observable.OnPropertyChangedCallback callback = new android.databinding.Observable.OnPropertyChangedCallback() {
            @Override
            public void onPropertyChanged(android.databinding.Observable dataBindingObservable, int propertyId) {
                if (dataBindingObservable == observableField) {
                    asyncEmitter.onNext(observableField.get());
                }
            }
        };
        observableField.addOnPropertyChangedCallback(callback);
    });
}
 
Example 2
Project: Java-EX   File: NullablePublisher.java   Source Code and License Vote up 4 votes
@Override
public Observable<T> observable() {
  return Observable.fromPublisher(get());
}
 
Example 3
Project: hoard   File: RxHoard2.java   Source Code and License Vote up 2 votes
/**
 * Same as {@link #retrieveAll()} but wrapped in a {@link Observable}.
 *
 * @return Observable that when subscribed will retrieve the key value pairs stored in
 * {@link Hoard} and provide them as a {@link Hoard.Pair}
 */
public Observable<Hoard.Pair> retrieveAllRx() {
  return Observable.fromPublisher(hoard.retrieveAllReactive());
}