July 2018
Intermediate to advanced
266 pages
7h 11m
English
Having functions that return an implementation of Job can be convenient in some scenarios, but it has the disadvantage of requiring the code to use join() or await() in order to suspend while a coroutine is being executed. What if we want to suspend as the default behavior? Let's design a repository using async functions and see what an implementation would look like. Let's start with the following data class:
data class Profile( val id: Long, val name: String, val age: Int)
Now let's design an interface of a client that retrieves profiles based on name or id. The initial design would look like this:
interface ProfileServiceRepository { fun fetchByName(name: String) : Profile fun fetchById(id: ...
Read now
Unlock full access