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

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.

主站蜘蛛池模板: 图们市| 资溪县| 济源市| 体育| 青冈县| 保靖县| 涟源市| 岳阳县| 新邵县| 平邑县| 团风县| 郑州市| 温州市| 安图县| 镶黄旗| 邛崃市| 浦县| 屏南县| 扎赉特旗| 土默特右旗| 拜泉县| 尖扎县| 始兴县| 多伦县| 普定县| 烟台市| 平乡县| 德保县| 平湖市| 嵩明县| 花垣县| 循化| 弥勒县| 竹溪县| 抚远县| 汨罗市| 格尔木市| 丽水市| 平舆县| 南部县| 民和|