What is the difference between launch/join and async/await in Kotlin coroutines?
Hi everyone! I started learning coroutines in Kotlin and got confused about two approaches: launch/join and async/await. They both seem to allow running tasks in parallel and waiting for their completion, but I don't understand when to use which.
I have a simple example: I need to download two files and merge them. I tried both approaches, but the results are different.
First approach with launch/join:
```kotlin
fun main() = runBlocking {
var result1 = ""
var result2 = ""
val job1 = launch {
delay(1000)
result1 = "File1 content"
}
val job2 = launch {
delay(1000)
result2 = "File2 content"
}
job1.join()
job2.join()
println("$result1 $result2")
}
```
Second approach with async/await:
```kotlin
fun main() = runBlocking {
val deferre
```
No answers yet.
Log in to leave an answer