mirror of
https://github.com/InsanusMokrassar/SauceNaoAPI.git
synced 2024-11-10 17:23:47 +00:00
23 lines
436 B
Kotlin
23 lines
436 B
Kotlin
package dev.inmo.saucenaoapi.utils
|
|
|
|
import kotlinx.coroutines.supervisorScope
|
|
|
|
interface SauceCloseable {
|
|
fun close()
|
|
}
|
|
|
|
inline fun <T> SauceCloseable.use(block: (SauceCloseable) -> T): T = try {
|
|
block(this)
|
|
} finally {
|
|
close()
|
|
}
|
|
|
|
@Deprecated("Useless")
|
|
suspend fun <T> SauceCloseable.useSafe(block: suspend (SauceCloseable) -> T): T = try {
|
|
supervisorScope {
|
|
block(this@useSafe)
|
|
}
|
|
} finally {
|
|
close()
|
|
}
|