I'm finding the naming of
Dispatchers.Main
quite unintuitive 😞. In a simple Swing app, the main (initial) thread and the UI thread are two different things. I'm trying to write an article talking about the two, and I literally can't find a nice way to explain it.
suspend fun main() {
println(Thread.currentThread()) // "Thread[main,…]" <- obviously the main thread, it says so in the name
withContext(Dispatchers.Main) {
println(Thread.currentThread()) // "Thread[AWT-EventQueue-0,…]" <- UI thread
}
}
Anybody got any suggestions for an intuitive way to explain it to newcomers? So far I'm stuck at "Dispatchers.Main runs code on the UI thread, which is not the same as the main thread, but it's called that because on Android it runs code on the main thread, which is usually (but not always) the same as the UI thread" 🤦😂 😭