Fixed typo in ES impl and CloseableWrapper
This commit is contained in:
parent
131dd44d38
commit
8f277853bd
@ -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()
|
||||
}
|
||||
}
|
||||
@ -4,7 +4,7 @@ package ru.landgrafhomyak.utility.closeable_state_1
|
||||
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
|
||||
public class OwnedErrorOnConcurrentAccesState : ErrorOnConcurrentAccessState {
|
||||
public class OwnedErrorOnConcurrentAccessState : ErrorOnConcurrentAccessState {
|
||||
public val _owner: Any
|
||||
|
||||
public constructor(owner: Any) : super() {
|
||||
@ -38,3 +38,15 @@ public inline fun <R> CloseableState.childES(
|
||||
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)
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user