-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.x: Add Single.onErrorResumeNext(Func)
- Loading branch information
1 parent
a42d0bf
commit afd6649
Showing
5 changed files
with
159 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/rx/internal/operators/SingleOperatorOnErrorResumeNext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package rx.internal.operators; | ||
|
||
import rx.Single; | ||
import rx.SingleSubscriber; | ||
import rx.exceptions.Exceptions; | ||
import rx.functions.Func1; | ||
import rx.plugins.RxJavaPlugins; | ||
|
||
public class SingleOperatorOnErrorResumeNext<T> implements Single.OnSubscribe<T> { | ||
|
||
private final Single<? extends T> originalSingle; | ||
private final Func1<Throwable, ? extends Single<? extends T>> resumeFunctionInCaseOfError; | ||
|
||
private SingleOperatorOnErrorResumeNext(Single<? extends T> originalSingle, Func1<Throwable, ? extends Single<? extends T>> resumeFunctionInCaseOfError) { | ||
if (originalSingle == null) { | ||
throw new NullPointerException("originalSingle must not be null"); | ||
} | ||
|
||
if (resumeFunctionInCaseOfError == null) { | ||
throw new NullPointerException("resumeFunctionInCaseOfError must not be null"); | ||
} | ||
|
||
this.originalSingle = originalSingle; | ||
this.resumeFunctionInCaseOfError = resumeFunctionInCaseOfError; | ||
} | ||
|
||
public static <T> SingleOperatorOnErrorResumeNext<T> withFunction(Single<? extends T> originalSingle, Func1<Throwable, ? extends Single<? extends T>> resumeFunctionInCaseOfError) { | ||
return new SingleOperatorOnErrorResumeNext<T>(originalSingle, resumeFunctionInCaseOfError); | ||
} | ||
|
||
public static <T> SingleOperatorOnErrorResumeNext<T> withOther(Single<? extends T> originalSingle, final Single<? extends T> resumeSingleInCaseOfError) { | ||
if (resumeSingleInCaseOfError == null) { | ||
throw new NullPointerException("resumeSingleInCaseOfError must not be null"); | ||
} | ||
|
||
return new SingleOperatorOnErrorResumeNext<T>(originalSingle, new Func1<Throwable, Single<? extends T>>() { | ||
@Override | ||
public Single<? extends T> call(Throwable throwable) { | ||
return resumeSingleInCaseOfError; | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void call(final SingleSubscriber<? super T> child) { | ||
final SingleSubscriber<? super T> parent = new SingleSubscriber<T>() { | ||
@Override | ||
public void onSuccess(T value) { | ||
child.onSuccess(value); | ||
} | ||
|
||
@Override | ||
public void onError(Throwable error) { | ||
try { | ||
resumeFunctionInCaseOfError.call(error).subscribe(child); | ||
} catch (Throwable innerError) { | ||
Exceptions.throwOrReport(innerError, child); | ||
} | ||
} | ||
}; | ||
|
||
child.add(parent); | ||
originalSingle.subscribe(parent); | ||
} | ||
} |
45 changes: 0 additions & 45 deletions
45
src/main/java/rx/internal/operators/SingleOperatorOnErrorResumeNextViaSingle.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters