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

ratpack.rx2.internal.ExecutionBackedSubscriber Maven / Gradle / Ivy

The newest version!
package ratpack.rx2.internal;

import io.reactivex.FlowableSubscriber;
import io.reactivex.exceptions.CompositeException;
import io.reactivex.exceptions.OnErrorNotImplementedException;
import io.reactivex.exceptions.UndeliverableException;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import ratpack.exec.Promise;
import ratpack.func.Action;

public class ExecutionBackedSubscriber implements FlowableSubscriber {
  private final Subscriber subscriber;

  public ExecutionBackedSubscriber(Subscriber subscriber) {
    this.subscriber = subscriber;
  }

  @Override
  public void onComplete() {
    try {
      subscriber.onComplete();
    } catch (final OnErrorNotImplementedException e) {
      Promise.error(e.getCause()).then(Action.noop());
    } catch (Exception e) {
      Promise.error(new UndeliverableException(e)).then(Action.noop());
    }
  }

  @Override
  public void onError(Throwable e) {
    try {
      subscriber.onError(e);
    } catch (final OnErrorNotImplementedException e2) {
      Promise.error(e2.getCause()).then(Action.noop());
    } catch (Exception e2) {
      Promise.error(new CompositeException(e, e2)).then(Action.noop());
    }
  }

  @Override
  public void onSubscribe(Subscription s) {
    try {
      subscriber.onSubscribe(s);
    } catch (final OnErrorNotImplementedException e) {
      Promise.error(e.getCause()).then(Action.noop());
    } catch (Exception e) {
      Promise.error(new UndeliverableException(e)).then(Action.noop());
    }
  }

  @Override
  public void onNext(T t) {
    try {
      subscriber.onNext(t);
    } catch (final OnErrorNotImplementedException e) {
      Promise.error(e.getCause()).then(Action.noop());
    } catch (Exception e) {
      Promise.error(new UndeliverableException(e)).then(Action.noop());
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy