Sanket Mehta
02/19/2020, 2:45 PMimport kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.runBlocking
import java.util.stream.IntStream
fun main() {
runBlocking {
val asyncs = IntStream.range(0, 6).mapToObj {
GlobalScope.async {
handleData("handler-$it")
}
}
asyncs.forEach {
runBlocking {
it.await()
}
}
}
}
private fun handleData(handlerName: String) {
println(handlerName)
while (true) {
}
}
Current output:
handler-0
Expected output:
handler-0
handler-1
handler-2
handler-3
handler-4
handler-5Andrzej
02/19/2020, 3:05 PMfun main() {
runBlocking {
val asyncs = IntStream.range(0, 6).mapToObj {
GlobalScope.async {
handleData("handler-$it")
}
}.toList()
asyncs.awaitAll()
}
}
Sanket Mehta
02/19/2020, 4:17 PMKroppeb
02/19/2020, 5:03 PM