Kotlin: withContext() vs Async-await

前端 未结 3 1048
栀梦
栀梦 2020-12-22 17:00

I have been reading kotlin docs, and if I understood correctly the two Kotlin functions work as follows :

  1. withContext(context): switches the contex
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-22 17:10

    When in doubt, remember this like a rule of thumb:

    1. If multiple tasks have to happen in parallel and final result depends on completion of all of them, then use async.

    2. For returning the result of a single task, use withContext.

提交回复
热议问题