Kotlin Async vs Launch

女生的网名这么多〃 提交于 2019-12-05 11:24:34

async does return a Deferred<>, while launch does only return a Job, both start a new coroutine. So it depends if you require a return value or not.

In your first example the launch does not return a value - the last println only produces an Unit. If you use async as in the second example, the overall result will be the same, but you create some useless Deferred<Unit> objects.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!