Lawrence
08/28/2022, 8:57 PMThrowable that were returned while handling the API. I came up with this code not sure if this is the optimal way to do so:
suspend fun scheduleCall(service: Service, handleError: (Throwable) -> Unit) =
(Schedule.doWhile<Either<Throwable, Data>> { it.isEmpty() }
.logOutput { it.mapLeft { throwable -> handleError(throwable) } })
.repeat { service.call() }
suspend fun callServices(
a: Service,
b: Service
): Either<List<Throwable>, String> {
val errors = mutableListOf<Throwable>()
val winner =
raceN(
<http://Dispatchers.IO|Dispatchers.IO>,
{ scheduleCall(a) { errors += it } },
{ scheduleCall(b) { errors += it } },
{ delay(60.seconds) })
return when (winner) {
is First -> "A".right()
is Second -> "B".right()
is Third -> errors.left()
}
}simon.vergauwen
08/29/2022, 7:12 AMscheduleCall with (a) and (b) not just of the winner of the race?Lawrence
08/29/2022, 3:29 PMsimon.vergauwen
08/29/2022, 3:34 PMfa, and fb. They both return Either<Throwable, Data>.
You need to run them in parallel until they succeed, with a timeout of 60s? If they don't succeed you want to know all errors that occurred for both fa and fb?
Or are do you need to race them in parallel until they succeed,....Lawrence
08/29/2022, 4:17 PMYou need to run them in parallel until they succeed, with a timeout of 60s? If they don't succeed you want to know all errors that occurred for bothYes, I am looking to implement something like that. Sorry about the confusionandfa?fb