July 2018
Intermediate to advanced
266 pages
7h 11m
English
Currently, we aren't storing the result of the other suspending functions. To do so, we need to create a more complete implementation of the state machine, which can be easy if we use CoroutineImpl as the base. In this case, we could create this private class outside of the function:
private class GetUserSummarySM: CoroutineImpl { var value: Any? = null var exception: Throwable? = null var cont: Continuation<Any?>? = null val id: Int? = null var profile: Profile? = null var age: Int? = null var terms: Terms? = null override fun doResume(data: Any?, exception: Throwable?) { this.value = data this.exception = exception getUserSummary(id, this) }}
Here we have done the following:
Read now
Unlock full access