https://kotlinlang.org logo
#orbit-mvi
Title
# orbit-mvi
e

expensivebelly

11/15/2019, 10:13 AM
Hello Orbiters. Quick question. What would be the easy way to achieve retry 3 times for a given network request while showing to the user
First/Second/Third retry attempt
and then either fail or succeed at that point? Thanks
k

kioba

11/15/2019, 12:15 PM
Are you looking for automatic retry or user interaction retry?
e

expensivebelly

11/15/2019, 2:19 PM
Automatic retry
k

kioba

11/15/2019, 5:26 PM
Copy code
perform("something")
  .on<ASD>
  .transform{  NetworkCallWithRetryAndStartWith() }
  .reduce{}
or you could use loopback
Copy code
perform("network")
  .on(
Event::class.java,
ErrorEvent::class.java
)
  .transform{  Network() }
  .loopBack{ if( error && event.count < 3) ErrorEvent else SuccessEvent }

perform("error show")
  .on(ErrorEvent::class.java)
  .reduce{ error }

perform("success show")
  .on(SuccessEvent::class.java)
  .reduce{ Success }
e

expensivebelly

11/16/2019, 2:43 AM
Cool thanks, I'll have a look at that
loopback
Can you use that for asynchronous sources as well, like, let's say I want to retry 3 times but only when there's network connection? Kind of what you can do with
retryWhen
k

kioba

11/16/2019, 10:37 AM
I would suggest to keep this in the transformer 🙂
We get to work with the Rx Operators in the transformer which is powerful enough to handle all the cases. Orbit with
.transform {}
,
.reduce{}
,
.loopback{}
keeps the MVI pattern clear and super easy to read but does not replace the RxStream
👍 1