Added Freezer to be able to freeze objects from common code (non-Native implementations just do nothing)
This commit is contained in:
parent
98056a520a
commit
42262babfa
|
@ -0,0 +1,14 @@
|
|||
package net.dankito.utils.multiplatform
|
||||
|
||||
|
||||
expect class Freezer() {
|
||||
|
||||
companion object {
|
||||
|
||||
fun <T> freeze(obj: T): T
|
||||
|
||||
fun isFrozen(obj: Any): Boolean
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package net.dankito.utils.multiplatform
|
||||
|
||||
import kotlin.native.concurrent.freeze
|
||||
import kotlin.native.concurrent.isFrozen
|
||||
|
||||
|
||||
actual class Freezer {
|
||||
|
||||
actual companion object {
|
||||
|
||||
actual fun <T> freeze(obj: T): T {
|
||||
return obj.freeze()
|
||||
}
|
||||
|
||||
actual fun isFrozen(obj: Any): Boolean {
|
||||
return obj.isFrozen
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package net.dankito.utils.multiplatform
|
||||
|
||||
|
||||
actual class Freezer {
|
||||
|
||||
actual companion object {
|
||||
|
||||
actual fun <T> freeze(obj: T): T {
|
||||
return obj // no op
|
||||
}
|
||||
|
||||
actual fun isFrozen(obj: Any): Boolean {
|
||||
return false // freezing is only possible on Kotlin/Native
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue