- Learning Concurrency in Kotlin
- Miguel Angel Castiblanco Torres
- 81字
- 2021-08-05 10:46:50
An asynchronous function with a flexible dispatcher
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.
推薦閱讀
- 演進(jìn)式架構(gòu)(原書第2版)
- Android Development with Kotlin
- Full-Stack Vue.js 2 and Laravel 5
- SQL基礎(chǔ)教程(視頻教學(xué)版)
- Learning Data Mining with R
- The Complete Coding Interview Guide in Java
- Linux:Embedded Development
- 低代碼平臺(tái)開發(fā)實(shí)踐:基于React
- PHP編程基礎(chǔ)與實(shí)踐教程
- OpenMP核心技術(shù)指南
- Python函數(shù)式編程(第2版)
- AMP:Building Accelerated Mobile Pages
- 分布式架構(gòu)原理與實(shí)踐
- Visual Basic語言程序設(shè)計(jì)基礎(chǔ)(第3版)
- 網(wǎng)絡(luò)工程方案設(shè)計(jì)與實(shí)施(第二版)