Alejandro Serrano.Mena
12/05/2024, 8:37 PMMichael Kaiser
12/08/2024, 4:18 PMarrow.fx.coroutines.Atomic
, changed quite a lot but I couldn't find any advice for migration! 😔
e.g. unsafe
and modify
weren't deprecated, but do not exist in 2.0.
`unsafe`is easy as it can just be replaced by invoke
.
But modify
doesn't look like it has a in place replacement. :-/Alejandro Serrano.Mena
12/08/2024, 5:15 PMmodify
you can use getAndUpdate
https://apidocs.arrow-kt.io/arrow-atomic/arrow.atomic/get-and-update.html or updateAndGet
https://apidocs.arrow-kt.io/arrow-atomic/arrow.atomic/update-and-get.htmlMichael Kaiser
12/08/2024, 5:27 PMfun <A, B> Atomic<A>.modify(f: (A) -> Pair<A, B>): B {
tailrec fun go(): B {
val a = this.get()
val (u, b) = f(a)
return if (!this.compareAndSet(a, u)) go() else b
}
return go()
}