Skip to content

Instantly share code, notes, and snippets.

@Axrorxoja
Created December 27, 2020 16:49
Show Gist options
  • Save Axrorxoja/e7c8592e6de7a9b2bcead3b3cec78b7d to your computer and use it in GitHub Desktop.
Save Axrorxoja/e7c8592e6de7a9b2bcead3b3cec78b7d to your computer and use it in GitHub Desktop.
Coroutine sequence launch
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
fun main() {
runBlocking {
launch {
val result1 = fun1()
println(result1)
val result2 = fun2()
println(result2)
val result3 = fun3()
println(result3)
val result4 = fun4()
println(result4)
}
}
}
suspend fun fun1(): Any {
delay(100)
return "fun1 finished"
}
suspend fun fun2(): Any {
delay(200)
return "fun2 finished"
}
suspend fun fun3(): Any {
delay(300)
return "fun3 finished"
}
suspend fun fun4(): Any {
delay(400)
return "fun3 finished"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment