kpgalligan
02/03/2020, 3:25 PMarnaud.giuliani
02/03/2020, 4:55 PMarnaud.giuliani
02/03/2020, 4:55 PMarnaud.giuliani
02/03/2020, 4:56 PMarnaud.giuliani
02/03/2020, 4:56 PMkpgalligan
02/03/2020, 4:57 PMarnaud.giuliani
02/03/2020, 4:59 PMarnaud.giuliani
02/03/2020, 5:00 PMkpgalligan
02/03/2020, 5:00 PMarnaud.giuliani
02/03/2020, 5:01 PMarnaud.giuliani
02/03/2020, 5:01 PMkpgalligan
02/06/2020, 3:19 PMkpgalligan
02/06/2020, 3:20 PMarnaud.giuliani
02/06/2020, 3:23 PMkpgalligan
02/06/2020, 3:32 PMarnaud.giuliani
02/06/2020, 3:40 PMarnaud.giuliani
02/06/2020, 3:41 PMkpgalligan
02/06/2020, 3:46 PMarnaud.giuliani
02/06/2020, 3:49 PMkpgalligan
02/06/2020, 4:04 PMkpgalligan
02/06/2020, 4:06 PMarnaud.giuliani
02/06/2020, 4:37 PMThe user should not be able to access something from another thread without somehow indicating that they’re aware they’re doing that. If we just auto-freeze, it’s not a great situation (in my opinion).sure
arnaud.giuliani
02/06/2020, 4:37 PMarnaud.giuliani
02/06/2020, 4:54 PMarnaud.giuliani
02/06/2020, 4:55 PMarnaud.giuliani
02/06/2020, 5:20 PMarnaud.giuliani
02/06/2020, 5:20 PMarnaud.giuliani
02/06/2020, 5:42 PMkpgalligan
02/06/2020, 5:42 PMkpgalligan
02/06/2020, 5:42 PMarnaud.giuliani
02/06/2020, 5:44 PMarnaud.giuliani
02/06/2020, 5:44 PMarnaud.giuliani
02/06/2020, 5:44 PMkpgalligan
02/06/2020, 5:45 PMarnaud.giuliani
02/06/2020, 5:45 PMarnaud.giuliani
02/06/2020, 6:29 PMarnaud.giuliani
02/06/2020, 6:29 PMarnaud.giuliani
02/06/2020, 6:30 PMarnaud.giuliani
02/06/2020, 6:30 PMarnaud.giuliani
02/06/2020, 6:31 PMarnaud.giuliani
02/06/2020, 6:31 PMarnaud.giuliani
02/07/2020, 8:54 AMMainIsolatedState
class a way to ensure stable reference in current thread?arnaud.giuliani
02/07/2020, 8:55 AMkpgalligan
02/07/2020, 12:44 PMinternal expect class MainIsolatedState<T:Any>(startVal: T) {
fun _get(): T
}
internal inline val <T:Any> MainIsolatedState<T>.value: T
get() {
assertMainThread()
return _get()
}
kpgalligan
02/07/2020, 12:46 PM.value
, it checks that you’re on the main thread. If so, it calls _get()
. On JVM, you could just use synchronized to make sure you’re getting it “safely”, but on native, we actually need to make sure it’s on the right threadkpgalligan
02/07/2020, 12:47 PMinternal actual class MainIsolatedState<T:Any> actual constructor(startVal: T) {
private val stableRef = StableRef.create(startVal)
init {
startVal.ensureNeverFrozen()
freeze()
}
actual fun _get(): T = stableRef.get()
}
kpgalligan
02/07/2020, 12:47 PMStableRef
essentially lets you get a pointer, and you can pass that pointer around, but when you call stableRef.get()
, if you’re not on the thread that state belongs to, you have big problems.kpgalligan
02/07/2020, 12:52 PM.value
, and there will be an exception if you’re not on the main thread. If the call should be able to be from another thread, there’s mainOrBlock
, which will block the caller and go to the main thread for that state (if configured to allow that)kpgalligan
02/07/2020, 12:55 PMaccessConfig {}
and accessInvoke {}
. Something like that. In the main-thread instance, accessConfig
would throw if not in main thread, and accessInvoke
would block and move to main thread. In multi-thread, accessConfig
and accessInvoke
would just wrap calls in synchronized, although doing that just to inject could be problematic for performance.kpgalligan
02/07/2020, 12:56 PMarnaud.giuliani
02/07/2020, 6:11 PMarnaud.giuliani
02/07/2020, 6:12 PMkpgalligan
02/07/2020, 6:57 PMkpgalligan
02/10/2020, 4:31 PMarnaud.giuliani
02/10/2020, 6:04 PMarnaud.giuliani
02/10/2020, 6:04 PMarnaud.giuliani
02/10/2020, 6:05 PM