Vivek Sharma
01/27/2021, 2:49 PMlaunch {
doingNetworkCall() // this is suspend function
}
// doing some work on main thread here like loading
so assume doingNetworkCall() is taking some time, till that time that function get suspended OR it just works in background thread and on completion it returns like callback and do other work
and if this work is getting suspended, then when it is getting resumed to achieve desired outputCasey Brooks
01/27/2021, 3:01 PMlaunch { }
block) and switch contexts as necessary to ensure things get run on the proper threads.
launch {
withContext(Dispatchers.Main) {
showProgressBar()
}
val resultFromApiCall = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
doingNetworkCall()
}
withContext(Dispatchers.Main) {
dismissProgressBar()
updateUiWithInfoFromApi(resultFromApiCall)
}
}
Vivek Sharma
01/27/2021, 3:06 PMlouiscad
01/27/2021, 3:35 PMCancellationException
)Vivek Sharma
01/27/2021, 4:48 PM