July 2018
Intermediate to advanced
266 pages
7h 11m
English
To better understand this, let's include a label where the execution starts, and also on each of the places were the execution can be resumed:
suspend fun getUserSummary(id: Int): UserSummary { // label 0 -> first execution logger.log("fetching summary of $id") val profile = fetchProfile(id) // label 1 -> resuming val age = calculateAge(profile.dateOfBirth) val terms = validateTerms(profile.country, age) // label 2 -> resuming return UserSummary(profile, age, terms)}
Now, let's pretend that we can somehow receive the label that indicates which part of the code to execute. Then, we could write a when statement to separate the code to be executed:
when(label) { 0 -> { // Label 0 -> first execution logger.log("fetching summary of
Read now
Unlock full access