Coroutine is black magic of Koltin! ❤

viewModelScope.launch(Dispatchers.IO) {
val id = getImageId()
val status = decodeImageById(id)

showTag("decoded image status = $status")
}
suspend fun getImageId(): String {

showTag("getting id..")

// Getting image from server
delay(3000)

return "5"

}
suspend fun decodeImageById(id: String): Int {

showTag("decoding image with id = $id")

// Decode heavy image which takes 5 secs to complete
delay(5000)

return 1

}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Zaeem Sattar

Zaeem Sattar

Senior Software engineer | Pakistan🇵🇰| Mobile App Developer | Making cool android apps from years