commonMain.kotlinx.io.core.Closeable.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlinx-io Show documentation
Show all versions of kotlinx-io Show documentation
IO support libraries for Kotlin
package kotlinx.io.core
expect interface Closeable {
fun close()
}
inline fun C.use(block: (C) -> R): R {
var closed = false
return try {
block(this)
} catch (first: Throwable) {
try {
closed = true
close()
} catch (second: Throwable) {
first.addSuppressedInternal(second)
}
throw first
} finally {
if (!closed) {
close()
}
}
}
@PublishedApi
internal expect fun Throwable.addSuppressedInternal(other: Throwable)
© 2015 - 2025 Weber Informatics LLC | Privacy Policy