Will this work as intended to block and then cancel the job if
currentStateFlow
changes?
Copy code
currentStateFlow.takeWhile { it == CurrentState.IncomingRing.WhatsApp }.collect()
s
Sam
11/12/2024, 10:49 AM
It's worth being precise with the terminology here: this code doesn't block (it suspends) and it doesn't cancel a job. It should work, though. You can also simplify to this:
Copy code
currentStateFlow.first { it != CurrentState.IncomingRing.WhatsApp }
State flows never emit duplicates, so by definition there'll be at most one emission of the
CurrentState.IncomingRing.WhatsApp
value before it changes. That probably doesn't change your implementation, though.
r
reactormonk
11/13/2024, 1:29 AM
Oi sorry, I meant to paste the full code, which has a
cancel()
after this line, oops. Ah neat idea with the simplification.