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

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.
主站蜘蛛池模板: 九龙城区| 筠连县| 米易县| 塔河县| 河间市| 永修县| 静宁县| 凤台县| 浦城县| 南华县| 台中县| 漠河县| 康平县| 修水县| 宁化县| 青州市| 随州市| 平乐县| 永兴县| 和平县| 阿坝县| 天峻县| 安平县| 南皮县| 色达县| 垦利县| 余干县| 池州市| 杭锦后旗| 石景山区| 涿鹿县| 丰都县| 遂昌县| 聂荣县| 清丰县| 沁源县| 自治县| 湘潭县| 侯马市| 江西省| 鄂托克旗|