Why `runBlocking` starts by default on a thread na...
# coroutines
m
Why
runBlocking
starts by default on a thread named "main" instead of using
Dispatchers.Default
?
Copy code
fun main() = runBlocking() {
    print(Thread.currentThread().name) // main
}

fun main() = runBlocking(Dispatchers.Default) {
    print(Thread.currentThread().name) // DefaultDispatcher-worker-1
}
j
It runs on the current thread you are on when you call it.
3
m
As the name says, it doesn't launch, it runs
m
@Marko Mitic This sounds convincing
k
On the other hand
suspend fun main() {}
actually does run on the default dispatcher
m
This is the point, like AFAIK everything else
Copy code
suspend fun main() = coroutineScope<Unit> {
    launch {
        print(Thread.currentThread().name) // DefaultDispatcher-worker-1
    }
}

suspend fun main() {
    GlobalScope.launch {
        print(Thread.currentThread().name) // DefaultDispatcher-worker-1
    }.join()
}