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

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.

主站蜘蛛池模板: 沧州市| 承德市| 灵川县| 瓦房店市| 平原县| 建平县| 澄迈县| 永丰县| 娄烦县| 名山县| 伊春市| 江西省| 望奎县| 尚志市| 吴忠市| 葵青区| 双鸭山市| 滨海县| 防城港市| 乌恰县| 闸北区| 厦门市| 苗栗县| 常熟市| 德令哈市| 武川县| 杂多县| 彰武县| 石首市| 三亚市| 博罗县| 桐柏县| 资溪县| 赤水市| 铜川市| 楚雄市| 揭西县| 上林县| 顺昌县| 遂川县| 双城市|