useAsync

suspend fun <T : AsyncCloseable, R> T.useAsync(block: suspend (T) -> R): R

Runs block with this resource and closes it afterwards, whatever block did. The close runs even when the caller is cancelled. A failure of the close after a failure of block is added to the first as suppressed.