Slide 14
Slide 14 text
Behind the Scenes
class CoroutinesReversed {
class Continuation(val label: Int, val context: Map, val error: Throwable?)
fun load(cont: Continuation) {
when (cont.label) {
0 -> {
cont.error?.let { throw it }
val url1 = cont.context["url1"] as String
val image1 = loadImage(url1)
load(Continuation(1, cont.context.plus("image1" to image1), null))
}
1 -> {
cont.error?.let { throw it }
val url2 = cont.context["url2"] as String
val image2 = loadImage(url2)
load(Continuation(2, cont.context.plus("image2" to image2), null))
}
2 -> {
cont.error?.let { throw it }
val image1 = cont.context["image1"] as Image
val image2 = cont.context["image2"] as Image
val result = composeImages(image1, image2)
load(Continuation(3, cont.context.plus("result" to result), null))
}
3 -> {
val result = cont.context["result"] as Image
displayImage(result)
}
}
}
fun load() = load(Continuation(0, emptyMap(), null))
}