July 2018
Intermediate to advanced
242 pages
8h 6m
English
In the end, our code is going to print the following output to the console:
getResults() is running in bacground. Main thread is not blocked.abcgetResults() completedTotal time elapsed: 1029 ms
We've successfully managed to transform the callback-style getResultsAsync(callback: (List<Result>) -> Unit) function into the clean form of a suspending function returning the results directly–suspend fun getResults(): List<Result>. In order to get rid of the original callback argument, we have used the suspendCoroutine() function provided by the standard library. The suspendCoroutine() function takes the block: (Continuation<T>) -> Unit function type as an argument. The Continuation interface is designed to allow us to resume the ...
Read now
Unlock full access