Skip to content

Instantly share code, notes, and snippets.

@MathiasSeguy-Android2EE
Created June 11, 2020 09:08
Show Gist options
  • Save MathiasSeguy-Android2EE/998e6c8a3aaade1449797ecbf3457e40 to your computer and use it in GitHub Desktop.
Save MathiasSeguy-Android2EE/998e6c8a3aaade1449797ecbf3457e40 to your computer and use it in GitHub Desktop.
Markdium-Chapter 9: Observable's action operators
/**
* Using the observableWithErrorSrc skip error items and retry twice
* @return
*/
public static Observable getObservableWithOnErrorRetry() {
//you can also return an empty Observable and then quit the Observable nicely
return observableWithErrorSrc
.retry(2);
}
/**
* OutPut result:
* value emitted is Monday
* value emitted is Monday
* value emitted is Monday
exception thrown java.lang.NullPointerException: onNext called with null. Null values are generally not allowed in 2.x operators and sources.
* java.lang.NullPointerException: onNext called with null. Null values are generally not allowed in 2.x operators and sources.
*/
@Test
public void testObservableWithOnErrorRecover() {
Answer9_ObservableActions.getObservableWithOnErrorRetry()
.subscribe(it -> System.out.println("value emitted is " + it),
th -> {
System.out.println("exception thrown " + th);
th.printStackTrace();
},
() -> System.out.println("onCompleteCalled"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment