diff --git a/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/HandleWrapper.kt b/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/HandleWrapper.kt new file mode 100644 index 0000000..0af47b3 --- /dev/null +++ b/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/HandleWrapper.kt @@ -0,0 +1,27 @@ +package ru.landgrafhomyak.utility.closeable_state_1 + +import kotlin.contracts.InvocationKind +import kotlin.contracts.contract + +public class HandleWrapper( + handle: H, + state: CloseableState, +) { + private val _unprotected = handle + private val _state: CloseableState = state + + public fun useHandle(method: (H) -> R): R { + contract { + callsInPlace(method, InvocationKind.EXACTLY_ONCE) + } + + return this._state.withUse { method(this._unprotected) } + } + + @ManualStateManipulation + private fun close() { + this._state.close() + } + + override fun toString(): String = "" +} \ No newline at end of file