resource
Construct a Resource from an allocating function acquire and a release function release.
import arrow.fx.coroutines.resource
import arrow.fx.coroutines.resourceScope
val resource = resource {
install({ 42.also { println("Getting expensive resource") } }) { r, exitCase ->
println("Releasing expensive resource: $r, exit: $exitCase")
}
}
suspend fun main(): Unit = resourceScope {
val res = resource.bind()
println("Expensive resource under use! $res")
}
Content copied to clipboard