Seems straight forward, but there are methods like...
# arrow
s
Seems straight forward, but there are methods like
tupledN
,
parTraverse
,
parSequence
,
bracketCase
,
guarantee
from
IO
which would need some replacement thats not built on
IO
a
AFAIK those already exist in arrow-fx-coroutines 🙂
s
yes, just skimmed through read me. Awesome. Thank you 🙂
s
Yes, all of this already exist! And even much more than there is currently in the IO module! Docs can currently be found here: https://arrow-kt.io/docs/next/apidocs/arrow-fx-coroutines/ Current efforts to improve docs for releasing: https://github.com/arrow-kt/arrow-fx/pull/248 All feedback is very welcome!
🤘 1
s
@simon.vergauwen I am not sure if you have heard of this : https://github.com/resilience4j/resilience4j But I use this for circuit breaking and time-limiter. Sits very nicely with coroutines and arrow’s
IO
Like this :
Copy code
data class UtilsHttpCommand(
    private val commandKey: String,
    private val executionTimeoutMillis: Long,
    val httpClient: HttpClient
) {

    val circuitBreaker: CircuitBreaker = AppConfig.circuitBreakerRegistry.circuitBreaker(commandKey)
    private val timeLimiterConfig: TimeLimiterConfig = TimeLimiterConfig
        .custom()
        .timeoutDuration(Duration.ofMillis(executionTimeoutMillis))
        .build()
    val timeLimiter: TimeLimiter = AppConfig.timeLimiterRegistry.timeLimiter(commandKey, timeLimiterConfig)

    inline fun <reified A> execute(request: HttpRequestBuilder): IO<A> {
        return IO.effect(httpClient.coroutineContext + MDCContext()) {
            circuitBreaker.executeSuspendFunction {
                timeLimiter.executeSuspendFunction { httpClient.request<A>(request) }
            }
        }.handleBackendResponse()
    }
}
handleBackendResponse()
is just a
Copy code
inline fun <reified A> IO<A>.handleBackendResponse(): IO<A> { ... }
where I do
IO.handleErrorWith
to convert `Ktor`’s httpClient error classes to my own
s
You will be able to do the exact same thing using
suspend
. We also have a
CircuitBreaker
implementation based on Monix which originally was inspired by Akka. https://arrow-kt.io/docs/next/apidocs/arrow-fx-coroutines/arrow.fx.coroutines/-circuit-breaker/index.html
❤️ 2