官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 西乌珠穆沁旗| 平遥县| 襄城县| 开原市| 三江| 芷江| 万荣县| 隆安县| 同心县| 慈溪市| 阆中市| 洛川县| 长子县| 兴仁县| 临西县| 金门县| 山阴县| 芷江| 江北区| 贡觉县| 利川市| 新巴尔虎右旗| 彭阳县| 景洪市| 宜丰县| 潼关县| 常山县| 彰武县| 白城市| 汉中市| 玛曲县| 扶余县| 泰宁县| 泌阳县| 永顺县| 改则县| 乐山市| 黄龙县| 波密县| 合水县| 镶黄旗|