Hello Orbiters. Quick question. What would be the ...
# orbit-mvi
e
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
Are you looking for automatic retry or user interaction retry?
e
Automatic retry
k
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
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
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