All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.polkadot.utils.RxUtils Maven / Gradle / Ivy

The newest version!
package org.polkadot.utils;

import com.onehilltech.promises.Promise;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;

public class RxUtils {

    public static  Observable fromPromise(Promise promise) {
        return Observable.create(new ObservableOnSubscribe() {
            @Override
            public void subscribe(ObservableEmitter emitter) throws Exception {
                promise.then((result) -> {
                    emitter.onNext(result);
                    emitter.onComplete();
                    return null;
                })._catch(err -> {
                    emitter.onError(err);
                    return null;
                });
            }
        });
    }

    public static  Observable fromPromise(Promise promise, ObservableOnSubscribe observableOnSubscribe) {
        return Observable.create(observableOnSubscribe);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy