obobo
12/21/2018, 1:43 PMdecorateCheckedSupplier(circuitBreaker) {
suspendingFunction() // compiler complains
}
How would I handle this? I've realized that I can wrap the suspendingFunction
call in an async
block, but then the circuitbreaker returns a Deferred
and always succeeds, which is not what I want. What I want, I think, is to have be able to call a suspending function from an arbitrary lambda.streetsofboston
12/21/2018, 2:01 PMrunBlocking
instead.obobo
12/21/2018, 2:02 PMrunBlocking
is the choice here?streetsofboston
12/21/2018, 2:03 PMrunBlocking
should be used to bridge non-suspend code that can block/wait with suspend code.gildor
12/21/2018, 2:12 PMmarcoferrer
12/21/2018, 3:34 PMmarcoferrer
12/21/2018, 3:56 PMsuspend fun doSomethingSuspending(){}
fun CoroutineScope.test(){
//using mono coroutine builder from coroutines reactor
mono{ doSomethingSuspending() }
.withCircuitBreaker(circuitBreaker)
.awaitFirst()
}
fun <T> Mono<T>.withCircuitBreaker(circuitBreaker: CircuitBreaker): Mono<T> =
this.transform(CircuitBreakerOperator.of(circuitBreaker))
marcoferrer
12/21/2018, 3:58 PM"io.github.resilience4j:resilience4j-circuitbreaker"
"io.github.resilience4j:resilience4j-reactor"
"org.jetbrains.kotlinx:kotlinx-coroutines-reactor"