DEV Community

Discussion on: async/await Crash Course

Collapse
 
jmfayard profile image
Jean-Michel πŸ•΅πŸ»β€β™‚οΈ Fayard • Edited

async/await is a big step forward for JavaScript

It still have a problem common with Promise is that you may launch your promise and forget to "await" or ".then()" it, and then you have still done your side effect but didn't wait for it. Of course you may say that it's the programmer who is stupid for doing a simple mistake, but in my opinion when thousands of programmers do the same mistake, it's the designer of the library that did one.

In Kotlin, coroutines have solved this:

  • suspending functions are awaiting by default, you don't need to await explicitely
  • Flow give you cold asynchronous streams - like in reactive sterams / RxJs / RxJava - while Promise and async/await are hot

GitHub logo Kotlin / kotlinx.coroutines

Library support for Kotlin coroutines

kotlinx.coroutines

official JetBrains project GitHub license Download

Library support for Kotlin coroutines with multiplatform support This is a companion version for Kotlin 1.3.61 release.

suspend fun main() = coroutineScope {
    launch {
       delay(1000)
       println("Kotlin Coroutines World!")
    }
    println("Hello")
}

Play with coroutines online here

Modules

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

I really love Kotlin for this.

Another easy for Kotlin is generators and yields.

Collapse
 
kumareth profile image
Kumar Abhirup

Nice info! Thanks a lot πŸ˜‹