- 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.
推薦閱讀
- Learning Cython Programming
- 在最好的年紀學Python:小學生趣味編程
- 深入淺出Prometheus:原理、應用、源碼與拓展詳解
- INSTANT Sencha Touch
- Functional Programming in JavaScript
- Scratch 3.0少兒編程與邏輯思維訓練
- Mastering Swift 2
- Unity Game Development Scripting
- Spring Boot企業級項目開發實戰
- 全棧自動化測試實戰:基于TestNG、HttpClient、Selenium和Appium
- 現代C++編程實戰:132個核心技巧示例(原書第2版)
- 軟件測試教程
- JSP程序設計實例教程(第2版)
- Struts 2.x權威指南
- Android移動應用開發項目教程