- 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.
推薦閱讀
- Vue.js 3.x快速入門
- ReSharper Essentials
- Software Testing using Visual Studio 2012
- Java虛擬機(jī)字節(jié)碼:從入門到實(shí)戰(zhàn)
- Mastering Swift 2
- Learn WebAssembly
- C語(yǔ)言課程設(shè)計(jì)
- Getting Started with Laravel 4
- Java圖像處理:基于OpenCV與JVM
- MySQL程序員面試筆試寶典
- Visual Studio Code 權(quán)威指南
- 從零開始:C語(yǔ)言快速入門教程
- Flutter從0基礎(chǔ)到App上線
- 鋁合金陽(yáng)極氧化與表面處理技術(shù)(第三版)
- 多接入邊緣計(jì)算實(shí)戰(zhàn)