Skip to content

Instantly share code, notes, and snippets.

@benman1
Last active September 30, 2019 13:36
Show Gist options
  • Save benman1/c0f3511ca21cc0a65eb766cc45c8f318 to your computer and use it in GitHub Desktop.
Save benman1/c0f3511ca21cc0a65eb766cc45c8f318 to your computer and use it in GitHub Desktop.
create a list asynchronously in Kotlin
import kotlinx.coroutines.*
fun run() = runBlocking {
val l: List<Deferred<Int>> = List(100_000) {
async {
delay(1000)
it
}
}
l.map { it -> it.await() }
}
fun main(args: Array<String>) {
val l = run()
println("finished running")
l.forEach { print("$it, ") }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment