Skip to content

Instantly share code, notes, and snippets.

@alokomkar
Created October 21, 2022 02:28
Show Gist options
  • Select an option

  • Save alokomkar/a1491e92c5c24bd0bbe4e30fdbacf683 to your computer and use it in GitHub Desktop.

Select an option

Save alokomkar/a1491e92c5c24bd0bbe4e30fdbacf683 to your computer and use it in GitHub Desktop.
Coroutine scope builder
// Sequentially executes doWorld followed by "Done"
fun main() = runBlocking {
doWorld()
println("Done")
}
// Concurrently executes both sections
suspend fun doWorld() = coroutineScope { // this: CoroutineScope
launch { // Coroutine 1
delay(2000L)
println("World 2")
}
launch { // Coroutine 2
delay(1000L)
println("World 1")
}
println("Hello")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment