Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.x: unified onErrorX and onExceptionResumeNext and fixed backpressure #3689

Merged
merged 1 commit into from
Feb 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/rx/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -6230,7 +6230,7 @@ public final Observable<T> onErrorResumeNext(final Func1<Throwable, ? extends Ob
* @see <a href="http://reactivex.io/documentation/operators/catch.html">ReactiveX operators documentation: Catch</a>
*/
public final Observable<T> onErrorResumeNext(final Observable<? extends T> resumeSequence) {
return lift(new OperatorOnErrorResumeNextViaObservable<T>(resumeSequence));
return lift(OperatorOnErrorResumeNextViaFunction.withOther(resumeSequence));
}

/**
Expand Down Expand Up @@ -6260,7 +6260,7 @@ public final Observable<T> onErrorResumeNext(final Observable<? extends T> resum
* @see <a href="http://reactivex.io/documentation/operators/catch.html">ReactiveX operators documentation: Catch</a>
*/
public final Observable<T> onErrorReturn(Func1<Throwable, ? extends T> resumeFunction) {
return lift(new OperatorOnErrorReturn<T>(resumeFunction));
return lift(OperatorOnErrorResumeNextViaFunction.withSingle(resumeFunction));
}

/**
Expand Down Expand Up @@ -6296,7 +6296,7 @@ public final Observable<T> onErrorReturn(Func1<Throwable, ? extends T> resumeFun
* @see <a href="http://reactivex.io/documentation/operators/catch.html">ReactiveX operators documentation: Catch</a>
*/
public final Observable<T> onExceptionResumeNext(final Observable<? extends T> resumeSequence) {
return lift(new OperatorOnExceptionResumeNextViaObservable<T>(resumeSequence));
return lift(OperatorOnErrorResumeNextViaFunction.withException(resumeSequence));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/rx/Single.java
Original file line number Diff line number Diff line change
Expand Up @@ -1411,7 +1411,7 @@ public final Single<T> observeOn(Scheduler scheduler) {
* @see <a href="http://reactivex.io/documentation/operators/catch.html">ReactiveX operators documentation: Catch</a>
*/
public final Single<T> onErrorReturn(Func1<Throwable, ? extends T> resumeFunction) {
return lift(new OperatorOnErrorReturn<T>(resumeFunction));
return lift(OperatorOnErrorResumeNextViaFunction.withSingle(resumeFunction));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,51 @@ public final class OperatorOnErrorResumeNextViaFunction<T> implements Operator<T

final Func1<Throwable, ? extends Observable<? extends T>> resumeFunction;

public static <T> OperatorOnErrorResumeNextViaFunction<T> withSingle(final Func1<Throwable, ? extends T> resumeFunction) {
return new OperatorOnErrorResumeNextViaFunction<T>(new Func1<Throwable, Observable<? extends T>>() {
@Override
public Observable<? extends T> call(Throwable t) {
return Observable.just(resumeFunction.call(t));
}
});
}

public static <T> OperatorOnErrorResumeNextViaFunction<T> withOther(final Observable<? extends T> other) {
return new OperatorOnErrorResumeNextViaFunction<T>(new Func1<Throwable, Observable<? extends T>>() {
@Override
public Observable<? extends T> call(Throwable t) {
return other;
}
});
}

public static <T> OperatorOnErrorResumeNextViaFunction<T> withException(final Observable<? extends T> other) {
return new OperatorOnErrorResumeNextViaFunction<T>(new Func1<Throwable, Observable<? extends T>>() {
@Override
public Observable<? extends T> call(Throwable t) {
if (t instanceof Exception) {
return other;
}
return Observable.error(t);
}
});
}

public OperatorOnErrorResumeNextViaFunction(Func1<Throwable, ? extends Observable<? extends T>> f) {
this.resumeFunction = f;
}

@Override
public Subscriber<? super T> call(final Subscriber<? super T> child) {
final ProducerArbiter pa = new ProducerArbiter();

final SerialSubscription ssub = new SerialSubscription();

Subscriber<T> parent = new Subscriber<T>() {

private boolean done = false;
private boolean done;

long produced;

@Override
public void onCompleted() {
Expand All @@ -70,12 +104,13 @@ public void onCompleted() {
public void onError(Throwable e) {
if (done) {
Exceptions.throwIfFatal(e);
RxJavaPlugins.getInstance().getErrorHandler().handleError(e);
return;
}
done = true;
try {
RxJavaPlugins.getInstance().getErrorHandler().handleError(e);
unsubscribe();

Subscriber<T> next = new Subscriber<T>() {
@Override
public void onNext(T t) {
Expand All @@ -96,7 +131,13 @@ public void setProducer(Producer producer) {
};
ssub.set(next);

long p = produced;
if (p != 0L) {
pa.produced(p);
}

Observable<? extends T> resume = resumeFunction.call(e);

resume.unsafeSubscribe(next);
} catch (Throwable e2) {
Exceptions.throwOrReport(e2, child);
Expand All @@ -108,6 +149,7 @@ public void onNext(T t) {
if (done) {
return;
}
produced++;
child.onNext(t);
}

Expand All @@ -117,9 +159,11 @@ public void setProducer(final Producer producer) {
}

};
child.add(ssub);
ssub.set(parent);

child.add(ssub);
child.setProducer(pa);

return parent;
}

Expand Down

This file was deleted.

111 changes: 0 additions & 111 deletions src/main/java/rx/internal/operators/OperatorOnErrorReturn.java

This file was deleted.

Loading