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
Michal Klimczak
08/06/2021, 10:32 AM
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
edrd
08/06/2021, 10:29 PM
What problem are you trying to solve?
l
langara
08/07/2021, 9:16 AM
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