igor.wojda
04/29/2020, 8:18 AMsuspend fun sleepSort(list: List<Int>): List<Int> {
val listInt = listOf(1, 2, 3)
val listDeferred = list.map {
GlobalScope.async {
println("start $it")
}
}
listDeferred.first().await()
return listOf()
}
The above code gives me this result
start 1
start 2
start 3
I wonder why all deferred jobs are launched instead of jus the first one 🤔octylFractal
04/29/2020, 8:19 AMlist.map
is not lazy -- it returns a List itself.asSequence()
firstigor.wojda
04/29/2020, 8:20 AMaraqnid
04/29/2020, 9:21 AM