I’m not sure if this is what you are looking for but the following should get the timing that you list in your example:
Copy code
source
.onStart{ delay(500) }
.collect {
...
}
n
Nick Allen
07/21/2022, 4:33 PM
If you read the
Flow
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
Copy code
coroutineScope {
source.collect {
launch {
delay(500)
//Move original collect code here
}
}
Nick Allen
07/21/2022, 4:40 PM
You could potentially leverage something like
flattenMerge
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.
Copy code
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()