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

io.voucherify.client.utils.RxUtils Maven / Gradle / Ivy

Go to download

Voucherify-java-sdk is a Java client (can be used in Android application as well) which was created to simplify integration with Voucherify backend (http://www.voucherify.io)

There is a newer version: 16.0.2
Show newest version
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