Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
suspend fun loadImage200(name: String) {
delay(2000) // simulate slow behaviour
}
fun loadImage404(name: String) {
throw RuntimeException("Image not found: $name")
}
fun main() {
runBlocking {
try {
val image1 = async { loadImage200("image1") }
val image2 = async { loadImage404("image2") }
image1.await()
image2.await()
} catch (e: Exception) {
println(e)
}
println("Sleeping...")
Thread.sleep(5000)
println("Loading images done.")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment