July 2018
Intermediate to advanced
266 pages
7h 11m
English
So, now that we have the ability to resume at a give point by using the label, we need to modify the other suspending functions that are called from getUserSummary(), so that they also receive CoroutineImpl. Let's say that we, as the compiler, have modified the fetchProfile() and validateTerms() functions so that they received a Continuation<Any?>—just like we did for getUserSummary()—and called doResume() upon the completion of their execution. Then we could invoke them like this:
when(state.label) { 0 -> { // Label 0 -> first execution logger.log("fetching summary of $id") fetchProfile(id, sm) return } 1 -> { // label 1 -> resuming calculateAge(profile.dateOfBirth) validateTerms(profile.country, age, sm) return } 2 -> // label ...
Read now
Unlock full access