美文网首页
kotlin协程并发

kotlin协程并发

作者: 飞哥278999401 | 来源:发表于2022-09-08 21:50 被阅读0次

scope.launch {
    supervisorScope {

        val newsDefered = async { fetchNews() }
        val adDefered = async { fetchAd() }

        val news = newsDefered.await()
        val ads = adDefered.await()

        refreshUi(news, ads)
    }
}

SupervisorJob,它的特点就是孩子的失败不会影响父亲,也不会影响兄弟。
现在广告和新闻加载互不影响,各自抛异常都不会影响对方。

相关文章

网友评论

      本文标题:kotlin协程并发

      本文链接:https://www.haomeiwen.com/subject/optnnrtx.html