Question: Should not `runBlocking(Dispatchers.Main...
# coroutines
j
Question: Should not
runBlocking(Dispatchers.Main) {}
be the same as running
Handler(Looper.getMainLooper()).post{}
on android?
g
Yes, it’s pretty close, Dispatchers.Main on Android uses Handler with main looper to dispatch coroutines UPD: just now realized that you use runBlocking, no, it’s not the same, because it’s blocking
j
I'm curious, because it does not seem to translate well when trying to for instance, for a webview javascript bridge, force the call to run on main thread. I can run and force the thread (without issues)
Copy code
@JavascriptInterface
        override fun back() {
            Handler(Looper.getMainLooper()).post {
                this@PlatformSpecific.back()
            }
        }
But running this:
Copy code
@JavascriptInterface
        override fun back() {
            runBlocking(Dispatchers.Main) {
                this@PlatformSpecific.back()
            }
        }
Seems to lock the thread switch entirly
g
Ohhh,
sorry, I just now got what you are doing
No, it;’s not the same
do not use runBlocking for this, it will block the thread
use
launch(Dispatchers.Main)
instead
j
Oh yeah.. I'm a retard you are of course correct. I'm not trying to run a blocking action at all..
g
Yeah, I just also was a bit confused by not-common combination of runBlocking and async handler in your question