Recently I've updated my ViewModel
to use new viewModelScope
. From its implementation, I see that Dispatchers.Main.immediate
is set as the default CoroutineDispatcher
for viewModelScope
.
So when printing the current Thread
in viewModelScope.launch
it gives Thread[main,5,main]
But here is my question. Although this runs in Main Thread, the following code works for me which performs a network call.
viewModelScope.launch {
userRepo.login(email, password)
}
Here userRepo.login(email, password)
is suspend
function, which calls Retrofit
suspend
function.
So how this works, if my Current Thread is Main Thread?