In Arrow 1.2.4, why is the construction of Circuit...
# arrow
k
In Arrow 1.2.4, why is the construction of CircuitBreaker a suspendable function? What strategy can I use to create a shared CircuitBreaker to be used across multiple API method calls?
s
Hey Kev, Honsetly, switch to 2.x.x 😅 There it's not suspend. It was suspend because in "pure FP libraries" you can argue that creating an
AtomicReference
is a side-effect and thus needs to be wrapped in
IO
(or
suspend
). It didn't make any sense in Kotlin (nor in Arrow-kt), it was a bad decision and we reverted it in 2.x.x. Besides the history rant, you can safely wrap in
runBlocking
and just extract it because it never suspend during construction. I think you can safely do this for KMP since it doesn't actually suspend.
Copy code
var breaker: CircuitBreaker
suspend {
    CircuitBreaker(..)
}.startCoroutine(Continuation(EmptyCoroutineContext) {
   breaker = it.getOrThrow()
})
k
Thanks @simon.vergauwen
I don’t know why i sent this to the main channel also, fat finger moment.