Added Freezer to be able to freeze objects from common code (non-Native implementations just do nothing)

This commit is contained in:
dankito 2020-07-14 17:07:53 +02:00
parent 98056a520a
commit 42262babfa
3 changed files with 53 additions and 0 deletions

View File

@ -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
}
}

View File

@ -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
}
}
}

View File

@ -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
}
}
}