Last active
September 30, 2019 13:36
-
-
Save benman1/c0f3511ca21cc0a65eb766cc45c8f318 to your computer and use it in GitHub Desktop.
create a list asynchronously in Kotlin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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