Daniele Segato
12/23/2020, 12:16 PMFlow.transformLatest() complete when upstream completes?
upstream
.transformLatest { state ->
emitAll(dataForState(state))
}
say upstream is
currentState
.takeWhile { state -> isCloseNowState(state) }
This would be easy if I had control of it, I could use transformWhile , what if I don't?
How do I cancel dataForState when upstream completes?
Actually, this is challenging even when I use transformWhile() cause it is not cancelling the previous one I'd need a transformLatestWhileDominaezzz
12/23/2020, 12:17 PMtransformWhile.Daniele Segato
12/23/2020, 12:18 PMobserveState
.takeWhile { state -> isStopState(state) }
comes from upstream / a function I've no control in?Dominaezzz
12/23/2020, 12:18 PMDaniele Segato
12/23/2020, 12:19 PMtransformLatest to stop when upstream completes?Daniele Segato
12/23/2020, 12:19 PMtransformWhile works perfectly if you control all the chain. I should have asked the question betterDominaezzz
12/23/2020, 12:25 PMonCompletion and emit a cancellation token.Daniele Segato
12/23/2020, 12:25 PMtransformWhile is not possible
what I would need is a transformLatestWhile
(see my modified question)Dominaezzz
12/23/2020, 12:26 PMDominaezzz
12/23/2020, 12:27 PMDaniele Segato
12/23/2020, 12:37 PMupstream
.map { it as MyState? }
.onComplete { emit(null) }
.transformLatest { state ->
if (state != null) {
emitAll(dataForState(state)
}
}
if I had a nullable emission I could have build a wrapper and did the sameDominaezzz
12/24/2020, 1:35 PM