You can also have a look at ConflatedBroadcastChan...
# coroutines
j
Thanks for your help!
b
looks similar to an extension function i use:
Copy code
suspend fun <T> BroadcastChannel<T>.waitUntil(value: T): T {
    consume {
        for (element in this)
            if (element == value)
                return value
    }

    throw CancellationException("channel closed before item received")
}
actually yours will spinlock, you probably want to do something about that
j
But
consume
will pop the element out of the queue, right?
I’m aware that it could spin forever, but my view was that it was the consumer’s responsibility to timeout or throw it away or whatever.
b
it's a broadcast channel, there's no problem with popping it out of (your subscription). It wont effect anyone else getting elements.
spinning forever can cause really bad performance or app lockups, you should really avoid it
j
Both good points, I'll take another look at it. Thanks!