krotki
02/27/2018, 1:17 PMJoe
02/27/2018, 5:09 PMfun <T> ConflatedBroadcastChannel<T>.valueOrWait(): T {
while (true) {
val result = this.valueOrNull
if (result != null) {
return result
}
}
}
bj0
02/27/2018, 5:55 PMsuspend 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")
}
Joe
02/27/2018, 6:28 PMconsume
will pop the element out of the queue, right?bj0
02/27/2018, 6:33 PMJoe
02/27/2018, 6:51 PM