-
Notifications
You must be signed in to change notification settings - Fork 111
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
Add a more intricate retryWhen example, with both exception type check and retry count #24
Conversation
…eck and retry count
Thanks for providing this example. That's imho a very good way of testing that the signatures of the methods make sense, and I have a suspicion that this might not be the case here. Currently, the signature looks as follows: def retryWhen(handler: Observable[Notification[Any]] => Observable[Any]): Observable[T] And I wonder why it's not like this: def retryWhen(handler: Observable[Throwable] => Observable[Any]): Observable[T] since the But maybe we can also retry if the source observable completes or emits a certain item. In that case, it would make sense to have the first signature, so that the The goal of the examples in |
Yeah, it took me a while to figure out how to extract the actual Though I'm glad the functionality exist, since I removed a lot of intricate boilerplate code in favour of this, it could definitely be simpler to use. As far as I understand, the current |
Ok, so let's ask @headinthebox and @benjchristensen why the signature of def retryWhen(handler: Observable[Throwable] => Observable[Any]): Observable[T] |
It was for consistency with repeatWhen. Because there is no value for onCompleted we used Observable[Notification[Any]]. Both repeatWhen and retryWhen use the same underlying implementation. I guess retryWhen could be Observable[Throwable] and repeatWhen could be Observable[Void]. |
I really like the two proposed signature changes. Maybe change Is it to late to change this for For reference, this how the submitted code would look like with the proposed signature change: @Test def retryWhenDifferentExceptionsExample(): Unit = {
var observableCreateCount = 1 // Just to support switching which Exception is produced
Observable[String]({ subscriber =>
println("subscribing")
if (observableCreateCount <= 2) {
subscriber.onError(new IOException("IO Fail"))
} else {
subscriber.onError(new RuntimeException("Other failure"))
}
observableCreateCount += 1
}).retryWhen({ throwableObservable =>
throwableObservable.zip(Observable.from(1 to 3)).flatMap({ case (error, retryCount) =>
error match {
// Only retry 2 times if we get a IOException and then error out with the third IOException.
// Let the other Exception's pass through and complete the Observable.
case _: IOException =>
if (retryCount <= 3) {
println("IOException delay retry by " + retryCount + " second(s)")
Observable.timer(Duration(retryCount, TimeUnit.SECONDS))
} else {
Observable.error(error)
}
case _ =>
println("got error " + error + ", will stop retrying")
Observable.empty
}
})
}).toBlocking.foreach(s => println(s))
} |
Yes, in Scala, I would prefer |
I would prefer if the API for RxScala was inline with RxJava as much as possible, barring difference in language idioms. So updating both would be better IMO. I could take a swing at doing PR's for both RxScala and RxJava during the weekend, if we feel it's not too late to change the RxJava signatures. |
- If RxJava is updated with the same signature changes with ReactiveX/RxJava#1720, the conversion from RxScala to RxJava can be simplified, without any external signature changes in RxScala.
The RxJava changes have been made. I'll release a new release candidate soon for you to depend on for RxScala. |
- If RxJava is updated with the same signature changes with ReactiveX/RxJava#1720, the conversion from RxScala to RxJava can be simplified, without any external signature changes in RxScala.
No description provided.