kotlin-coroutines

What does suspend function mean in Kotlin Coroutine

為{幸葍}努か 提交于 2019-11-27 04:16:56
问题 I'm reading Kotlin Coroutine and know that it is based on suspend function. But what does suspend mean? Coroutine or function gets suspended? From https://kotlinlang.org/docs/reference/coroutines.html Basically, coroutines are computations that can be suspended without blocking a thread I heard people often say "suspend function". But I think it is the coroutine who gets suspended because it is waiting for the function to finished? "suspend" usually means "cease operation", in this case the

Can “experimental” Kotlin coroutines be used in production?

你离开我真会死。 提交于 2019-11-26 22:42:46
问题 Can Kotlin coroutines be used in production, and what does their experimental status mean? 回答1: UPDATE : Kotlin coroutines are no longer experimental as of Kotlin 1.3. Kotlin coroutines can and should be used in production. That was the chief reason to officially release them in Kotlin 1.1. Having released them, the JetBrains team had committed to maintain backwards compatibility with respect to any changes that are introduced to them in the minor releases as they evolve, while allowing

What is the difference between launch/join and async/await in Kotlin coroutines

北慕城南 提交于 2019-11-26 22:30:09
问题 In the kotlinx.coroutines library you can start new coroutine using either launch (with join ) or async (with await ). What is the difference between them? 回答1: launch is used to fire and forget coroutine . It is like starting a new thread. If the code inside the launch terminates with exception, then it is treated like uncaught exception in a thread -- usually printed to stderr in backend JVM applications and crashes Android applications. join is used to wait for completion of the launched