Nick Williams
02/14/2021, 2:45 PMAlex Vasilkov
02/14/2021, 3:07 PMFlow.comabine
docs:
Returns a [Flow] whose values are generated with [transform] function by combining the most recently emitted values by each flow.I think this is what you would expect from this kind of operator. “Latest” in operators like
flatMapLatest
has a bit different meaning, it actually subscribes to latest produced Flow
and unsubscribes from any previous flows (like RxJava’s switchMap
).wasyl
02/14/2021, 3:10 PMtransform
block and new values are emitted from the combined flows, then the transformation is not cancelled. If you want cancellation then I suppose the simplest way would be moving the work you want cancelled to a separate, *Latest
operator, for example instead of
flow1
.combine(flow2) { a, b -> heavyTransform(a, b) }
you can do
flow1
.combine(flow2) { a, b -> a to b }
.mapLatest { (a, b) -> heavyTransform(a, b) }
Nick Williams
02/14/2021, 3:21 PM