Amritansh
11/23/2020, 9:48 PMTijl
11/23/2020, 9:59 PMAtomicReference
and annotate with @SharedImmutable
Amritansh
11/23/2020, 10:00 PMAmritansh
11/23/2020, 10:00 PMTijl
11/23/2020, 10:01 PMTijl
11/23/2020, 10:01 PMTijl
11/23/2020, 10:02 PMexpect
a var
, and on Native implement get and set and redirect it to an AtomicReference
Amritansh
11/23/2020, 10:10 PMBenjamin Charais
11/23/2020, 10:15 PMclass MyVarSingleton private constructor(
val title: String,
val description: String
) {
@Suppress("VARIABLE_IN_SINGLETON_WITHOUT_THREAD_LOCAL")
companion object {
private var instance: MyVarSingleton? = null
private val mutex = Mutex(false)
suspend fun getInstance(): MyVarSingleton {
mutex.withLock {
return instance ?: throw AssertionError("Must call Init before getting instance")
}
}
suspend fun setInstance(title: String, description: String) {
if (instance != null) throw AssertionError("Can not re-initialize singleton instance")
mutex.withLock {
instance = MyVarSingleton(title, description)
}
}
}
}
Benjamin Charais
11/23/2020, 10:16 PMBenjamin Charais
11/23/2020, 10:30 PMAmritansh
11/23/2020, 11:08 PM