closeWith

infix fun <R, E : Exception, T> T.closeWith(block: (T) -> Unit): T

Provides a handy way to close resources. The specified block of code that is always called after result block has finished, even on failures caused by undefined Throwables or Exceptions.