美文网首页
Kotlin协程 Coroutines

Kotlin协程 Coroutines

作者: zhujunhua | 来源:发表于2020-05-29 15:16 被阅读0次

除了由不同的构建器提供协程作用域之外(runBlocking),还可以使用 coroutineScope构建器声明自己的作用域.

runBlockingcoroutineScope 可能看起来很类似,
相同点:
因为它们都会等待其协程体以及所有子协程结束。
这两者的主要区别在于:
runBlocking => 会 阻塞 当前线程来等待,
coroutineScope => 只是挂起,会释放底层线程用于其他用途。
由于存在这点差异,runBlocking 是常规函数,而 coroutineScope 是挂起函数。

相关文章

网友评论

      本文标题:Kotlin协程 Coroutines

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