scoped

inline fun <T> scoped(block: (scope: CloseableScopeRegistrar) -> T): T

Allows executing registered callbacks after the function execution, even in case of an execution error.

Example:

scoped { scope ->
val file = ZipFile(this).onClose(scope, "for zip file") //Closes Autocloseable at the end of `scoped` block
scope.register {
println("Some log")
}
}