Dean Djermanović
07/21/2022, 1:22 PMval source = flow {
emit(1)
delay(200)
emit(2)
delay(200)
emit(3)
}
source
.onEach { delay(500) }
.collect {
...
}
I want my items to be collected after:
1 - 500ms
2 - 700ms
3 - 900msJoseph Hawkes-Cates
07/21/2022, 4:29 PMsource
.onStart{ delay(500) }
.collect {
...
}Nick Allen
07/21/2022, 4:33 PMFlow interface docs, it guarantees that items are collected sequentially, so it's not possible in the way you are thinking.
However you can launch from collect
coroutineScope {
source.collect {
launch {
delay(500)
//Move original collect code here
}
}Nick Allen
07/21/2022, 4:40 PMflattenMerge which has optional param to limit concurrency. One Flow must emit items sequentially but if you turn it into many `Flow`s then the restriction doesn't apply.
source.flattenMerge {
flow {
delay(500)
//Move original collect code here
//Or could emit here so the collect below gets items and that part is sequential.
}
}
.collect()Dean Djermanović
07/25/2022, 6:28 AM