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

Coroutine dispatcher

In order to decide what thread to start or resume a coroutine on, a coroutine dispatcher is used. All coroutine dispatchers must implement the CoroutineDispatcher interface:

  • DefaultDispatcher: Currently it is the same as CommonPool. In the future, this may change.
  • CommonPool: Executes and resumes the coroutines in a pool of shared background threads. Its default size makes it optimal for use in CPU-bound operations.
  • Unconfined: Starts the coroutine in the current thread (the thread from which the coroutine was invoked), but will resume the coroutine in any thread. No thread policy is used by this dispatcher.

Along with these dispatchers, there are a couple of builders that can be used to define pools or threads as needed:

  • newSingleThreadContext() to build a dispatcher with a single thread; the coroutines executed here will be started and resumed in the same thread, always.
  • newFixedThreadPoolContext() creates a dispatcher with a pool of threads of the given size. The runtime will decide which thread to use when starting and resuming the coroutines executed in the dispatcher.
主站蜘蛛池模板: 托里县| 察隅县| 江口县| 汉寿县| 理塘县| 浦城县| 铜山县| 陵水| 瓮安县| 铜山县| 壤塘县| 新安县| 朝阳县| 余庆县| 嫩江县| 库尔勒市| 茶陵县| 建瓯市| 改则县| 阿城市| 涡阳县| 海丰县| 当阳市| 北辰区| 繁昌县| 青神县| 黔南| 南昌市| 陇南市| 高清| 阜城县| 宜兴市| 苏尼特左旗| 资中县| 波密县| 萨嘎县| 本溪市| 绥宁县| 鹤壁市| 福清市| 建昌县|