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

com.stanfy.enroscar.async.internal.ObservableTools Maven / Gradle / Ivy

There is a newer version: 2.0.alpha3
Show newest version
package com.stanfy.enroscar.async.internal;

import com.stanfy.enroscar.async.AsyncObserver;

import rx.Observable;
import rx.Subscriber;

/**
 * Provides tools for creating special {@link rx.Observable}s.
 * @author Roman Mazur - Stanfy (http://stanfy.com)
 */
public final class ObservableTools {

  private ObservableTools() { /* hidden */ }

  public static  Observable loaderObservable(final int loaderId,
                                                   final LoaderDescription description) {
    return Observable.create(new Observable.OnSubscribe() {
      @Override
      public void call(final Subscriber subscriber) {
        description.addObserver(loaderId, new AsyncObserver() {
          @Override
          public void onError(final Throwable e) {
            subscriber.onError(e);
          }

          @Override
          public void onResult(final D data) {
            subscriber.onNext(data);
          }

          @Override
          public void onReset() {
            subscriber.onCompleted();
          }
        });
      }
    });
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy