Hi, what is the prettiest way to check if I'm on m...
# multiplatform
l
Hi, what is the prettiest way to check if I'm on main thread (and throw otherwise)? I guess inside coroutine it should be sth like:
check(coroutineContext[ContinuationInterceptor] === Dispatchers.Main) { "TreeUiModel.logic must run o main!" }
But how to do it outside? (from regular function without coroutine scope/context)
1
m
I was just using expect/actual for this tbh. Not sure how you would do it otherwise, I'm not aware on any common abstraction over threads in common code
e
What problem are you trying to solve?
l
I try to make sure my app business logic is correctly confined to main thread, so I don't have to worry about synchronization. Btw my code above is not correct, because for example jetpack compose uses other dispatcher (AndroidUiDispatcher.Main) for main thread instead of Dispatchers.Main