Will this work as intended to block and then cance...
# coroutines
r
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
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
Oi sorry, I meant to paste the full code, which has a
cancel()
after this line, oops. Ah neat idea with the simplification.