Kotlin Coroutines choosing Dispatcher

被刻印的时光 ゝ 提交于 2020-01-24 09:29:29

问题


I'm trying to figure out which Dispatcher to use in what case.

I read some documentation and came up with this:

  • Default → CPU work
  • Main → main (update UI)
  • Unconfined
  • IO → writing file / network tasks

Is this right?

What about Unconfined?


回答1:


You're right in your assumptions about the dispatcher types. Unconfined dispatcher –

A coroutine dispatcher that is not confined to any specific thread

Unconfined dispatcher is appropriate when coroutine does not consume CPU time nor updates any shared data (like UI) that is confined to a specific thread.

You can read more about it here and here



来源:https://stackoverflow.com/questions/57109266/kotlin-coroutines-choosing-dispatcher

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