Extension function for simple AutoCloseable registration in closeable scope
Allows executing registered callbacks after the function execution, even in case of an execution error.