undermark5
01/24/2023, 4:28 PMcollectLatest
which will cancel and restart the action when a new value is emitted, and I see there are deprecated combineLatest
functions, however, they say to replace with combine
, does that mean that combine
will cancel the transformation when a new value is emitted from any of the upstream flows? If not, how would I achieve that behavior? I would expect that combineLatest
would do similar things to collectLatest
but as I said, those methods are marked as deprecated. Am I missing something in the documentation?undermark5
01/24/2023, 4:37 PMcombine
to produce a tuple of all of the values, and then pair that with collectLatest
, however, what if part of my combine
action requires some heavy computation that if a new value comes in, there isn’t any point in completing?
Or is one expected to do the above aggregation and then chain into a transformLatest
?wasyl
01/24/2023, 4:46 PMdoes that mean thatwill cancel the transformation when a new value is emitted from any of the upstream flows?combine
wasyl
01/24/2023, 4:47 PMcollectLatest
name was primarily a helper for migration from RxJavaundermark5
01/24/2023, 5:42 PMundermark5
01/24/2023, 6:18 PMcollectLatest
docs)
suspend fun main() {
val flow1 = flow {
emit(1)
delay(50)
emit(2)
}
var count = 0
val flow2 = flow {
while(count < 50) {
emit(count++)
delay(50)
}
}
val combined = flow1.combine(flow2) { val1, val2 ->
println("computing $val1 + $val2")
delay(100)
println("result ${val1 + val2}")
}
combined.collect()
}
seems to indicate that it does not in fact cancel the transformation. (I’m also not seeing anything in the implementation that would cancel it either).
Plus running through some issues on github, it would seem that combine
does in fact not cancel the work every time a new value is emitted from any upstream.wasyl
01/24/2023, 7:14 PMcombine
would cancel, especially since the transform
function is suspendable, otherwise why is that needed?wasyl
01/24/2023, 7:18 PMStylianos Gakis
01/27/2023, 12:54 AMundermark5
01/30/2023, 5:51 PMcombine
with a transformLatest
is probably what should be happening anyway.
That being said, if such usage is frequent, it would add a bit of boilerplate that could be avoided if they were merged, especially if all the combine
is doing is grouping the values into a tuple only to get destructured in the chained transformLatest
, which is why a proposal such as combineTransformLatest
makes sense.