useCloseable<R> function

R useCloseable<R>(
  1. Closeable resource,
  2. R fn(
    1. Closeable p0
    )
)

Runs passed function and closes this resource after it Closes the resource even if the function throws. The first exception thrown is propagated, if both the function and the close throw, the exception from the function is propagated

Implementation

R useCloseable<R>(
  Closeable resource,
  R Function(Closeable p0) fn,
) {
  return resource.runAndClose(fn);
}