Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

combining pagingData 3 flow with another flow

I have a pagingData flow object and i want to combine it with a different flow of fused location so it will be processed accordingly with each item of the pagingdata list .

val point : Flow<Point> 
val pagingDate : Flow<PagingData>

i tried to use combine and combineTransform but it seem to not work as when the point is updating app crashes and shows this error message related to pagingData 3 can't be emited twice

java.lang.IllegalStateException: Attempt to collect twice from pageEventFlow, which is an illegal operation. Did you forget to call Flow<PagingData<*>>.cachedIn(coroutineScope)?

what are my options here to transform pagingdata items with streamed data ?

like image 669
joghm Avatar asked Jun 28 '26 12:06

joghm


1 Answers

Just following up here since others may hit this issue although OP didn't update their answer yet.

This is typically due to usage of .combine or similar operators which would repeat the latest emitted value from a Flow, causing the same instance to be used twice. To prevent this you can call .cachedIn(scope) before .combine() so that the Flow is multicasted, giving you a new instance of PagingData with cached data preloaded.

like image 136
dlam Avatar answered Jun 30 '26 02:06

dlam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!