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

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.

主站蜘蛛池模板: 新龙县| 大姚县| 汉川市| 大石桥市| 辽阳市| 木里| 五寨县| 台中县| 临沭县| 永年县| 漳平市| 彰化市| 长丰县| 肃南| 沂水县| 新乡市| 岫岩| 岳阳市| 景泰县| 台东县| 增城市| 南皮县| 和硕县| 三江| 于都县| 元氏县| 铜山县| 毕节市| 普兰店市| 黄冈市| 昌黎县| 上思县| 天峨县| 沂水县| 江山市| 德化县| 深州市| 长汀县| 图木舒克市| 凯里市| 永寿县|