윤동환
09/13/2023, 12:15 AM/-- no1
val job = async(dispatcher) { /** do something */ }
/** do other processes */
val result = job.await()
/-- no2
val result = withContext(dispatcher) { /** do something */ }
Joffrey
09/13/2023, 1:01 AMJoffrey
09/13/2023, 1:02 AMwithContext
CLOVIS
09/13/2023, 1:00 PMval job = async(dispatcher) { … }
val result = job.await()
is the same thing (but very slightly faster) than:
val job = async {
withContext(dispatcher) { … }
}
val result = job.await()
Therefore, your question is "what is the difference between async { withContext(…) {…} }
and just withContext(…) {…}
"; and the answer is "`async` creates another coroutine that runs concurrently".myanmarking
09/14/2023, 4:00 PM윤동환
09/24/2023, 11:16 PMwithContext()
윤동환
09/24/2023, 11:19 PMJoffrey
09/25/2023, 12:33 AMwithContext(NonCancellable) { ... }
if you want to run some cleanup (suspending) code that cannot be cancelled.