io.voucherify.client.utils.RxUtils Maven / Gradle / Ivy
package io.voucherify.client.utils;
import io.voucherify.client.callback.VoucherifyCallback;
import io.voucherify.client.error.VoucherifyError;
import rx.Observable;
import rx.functions.Action1;
import rx.functions.Func0;
import rx.schedulers.Schedulers;
import java.util.concurrent.Executor;
public final class RxUtils {
public static VoucherifyCallback subscribe(final Executor executor, Observable observable, final VoucherifyCallback callback) {
observable
.subscribe(
new Action1() {
@Override
public void call(final R r) {
executor.execute(new Runnable() {
@Override
public void run() {
callback.onSuccess(r);
}
});
}
},
new Action1() {
@Override
public void call(final Throwable throwable) {
executor.execute(new Runnable() {
@Override
public void run() {
callback.onFailure(VoucherifyError.from(throwable));
}
});
}
});
return callback;
}
public abstract static class DefFunc implements Func0> {
@Override
public final Observable call() {
return Observable.just(method());
}
public abstract T method();
}
public static Observable defer(DefFunc func) {
return Observable.defer(func).subscribeOn(Schedulers.io());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy