Method to create child refcounters
This commit is contained in:
parent
8bf13d0f69
commit
5ac9133813
@ -15,7 +15,7 @@ buildscript {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "ru.landgrafhomyak.utility"
|
group = "ru.landgrafhomyak.utility"
|
||||||
version = "0.3"
|
version = "0.4"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|||||||
@ -91,4 +91,41 @@ public sealed class MayBeClosedReferenceCounter {
|
|||||||
else
|
else
|
||||||
return "<ref counter [${refcntCached}]>"
|
return "<ref counter [${refcntCached}]>"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("LEAKED_IN_PLACE_LAMBDA", "WRONG_INVOCATION_KIND")
|
||||||
|
@JvmName("child")
|
||||||
|
public fun <R> child(errMessageClosed: String, errExistRefs: String, scope: (MayBeClosedReferenceCounter) -> R): R {
|
||||||
|
contract {
|
||||||
|
callsInPlace(scope, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
|
||||||
|
_Platform.jvm_assertNotNull(errMessageClosed, "param: errMessageClosed")
|
||||||
|
_Platform.jvm_assertNotNull(errExistRefs, "param: errExistRefs")
|
||||||
|
_Platform.jvm_assertNotNull(scope, "param: scope")
|
||||||
|
|
||||||
|
this.withRef {
|
||||||
|
return CloseableReferenceCounter.autoClosed(
|
||||||
|
errMessageClosed = errMessageClosed,
|
||||||
|
errExistRefs = errExistRefs,
|
||||||
|
scope = scope
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("LEAKED_IN_PLACE_LAMBDA", "WRONG_INVOCATION_KIND")
|
||||||
|
@JvmName("child_inheritErrMessage")
|
||||||
|
public fun <R> child_inheritErrMessage(errExistRefs: String, scope: (MayBeClosedReferenceCounter) -> R): R {
|
||||||
|
contract {
|
||||||
|
callsInPlace(scope, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
|
||||||
|
_Platform.jvm_assertNotNull(errExistRefs, "param: errExistRefs")
|
||||||
|
_Platform.jvm_assertNotNull(scope, "param: scope")
|
||||||
|
|
||||||
|
return this.child(
|
||||||
|
errMessageClosed = this._errMessageClosed,
|
||||||
|
errExistRefs = errExistRefs,
|
||||||
|
scope = scope
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user