[history] Contracts for decorator functions

This commit is contained in:
Andrew Golovashevich 2025-03-19 21:59:44 +03:00
parent 28b3224e42
commit 5a49c43a4f

View File

@ -1,5 +1,7 @@
package ru.landrafhomyak.utility.reference_counter
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
import kotlinx.atomicfu.AtomicLong
import kotlinx.atomicfu.atomic
import kotlinx.atomicfu.update
@ -21,6 +23,9 @@ internal class CloseableReferenceCounter(private val _errMessage: String) {
}
inline fun <R> tryIncref(block: () -> R): R {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
this.incref()
return safeAutoClose2(onError = this::decref, action = block)
}
@ -34,6 +39,9 @@ internal class CloseableReferenceCounter(private val _errMessage: String) {
}
inline fun <R> tryDecref(block: () -> R): R {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
this.checkNotClosed()
return safeAutoClose2(onSuccess = this::decref, action = block)
}