July 2018
Intermediate to advanced
266 pages
7h 11m
English
We can bring back some flexibility to this function by making the dispatcher an optional parameter of the function:
private val defDsp = newSingleThreadContext(name = "ServiceCall")private fun asyncLoadNews(dispatcher: CoroutineDispatcher = defDsp) = launch(dispatcher) { ...}
This approach has more flexibility, since now the caller can use a specific CoroutineDispatcher to run this code, but it still has the downside of being explicit only if an appropriate name is given to the function.
Read now
Unlock full access