Fixed typo in ES impl and CloseableWrapper

This commit is contained in:
Andrew Golovashevich 2025-08-23 23:42:34 +03:00
parent 131dd44d38
commit 8f277853bd
3 changed files with 51 additions and 1 deletions

View File

@ -0,0 +1,38 @@
package ru.landgrafhomyak.utility.closeable_state_1
public class CloseableStateCloseableWrapper(
private val _parent: CloseableState.ExternallySynchronized,
private val _self: CloseableState.ExternallySynchronized
) : CloseableState.ExternallySynchronized {
override val isInUse: Boolean by this._self::isInUse
override val isClosed: Boolean by this._self::isInUse
override fun throwClosed(): Nothing =
this._self.throwClosed()
override fun throwInUse(): Nothing =
this._self.throwInUse()
override fun assertNotClosed(): Unit =
this._self.assertNotClosed()
@ManualStateManipulation
override fun startUsage() {
this._self.tryStartUsage {
this._parent.startUsage()
}
}
@ManualStateManipulation
override fun finishUsage() {
this._self.tryFinishUsage {
this._parent.finishUsage()
}
}
@ManualStateManipulation
override fun close() {
this._self.close()
}
}

View File

@ -4,7 +4,7 @@ package ru.landgrafhomyak.utility.closeable_state_1
import kotlin.contracts.ExperimentalContracts import kotlin.contracts.ExperimentalContracts
public class OwnedErrorOnConcurrentAccesState : ErrorOnConcurrentAccessState { public class OwnedErrorOnConcurrentAccessState : ErrorOnConcurrentAccessState {
public val _owner: Any public val _owner: Any
public constructor(owner: Any) : super() { public constructor(owner: Any) : super() {

View File

@ -37,4 +37,16 @@ public inline fun <R> CloseableState.childES(
action = { scope(childState) }, action = { scope(childState) },
finally = childState::close finally = childState::close
) )
}
@OptIn(ManualStateManipulation::class)
public inline fun <R> CloseableState.ExternallySynchronized.closeableWrapper(
constructor: () -> CloseableState.ExternallySynchronized = ::ErrorOnConcurrentAccessState,
scope: (CloseableState.ExternallySynchronized) -> R,
): R {
contract {
callsInPlace(constructor, InvocationKind.EXACTLY_ONCE)
callsInPlace(scope, InvocationKind.EXACTLY_ONCE)
}
return CloseableStateCloseableWrapper(this, constructor()).use(scope)
} }