resourceScope
The resourceScope function creates the ResourceScope instances, runs the user action while allocating the installed resources. upon ExitCase.Completed, ExitCase.Cancelled or ExitCase.Failure runs all the release
finalizers.
suspend fun main(): Unit = resourceScope {
val dataSource = install({
DataSource().also { it.connect() }
}) { ds, _ -> ds.close() }
println("Using data source: ${dataSource.users()}")
}
Content copied to clipboard