Dan Lowe
11/24/2019, 8:01 AMBroadcastChannel
but ignore any items that may already be in that channel at the time of subscription. Is this possible? (example in thread)Dan Lowe
11/24/2019, 8:01 AMval demoScope = CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO>)
val myBroadcastChannel = BroadcastChannel<String>(Channel.CONFLATED)
myBroadcastChannel.send("1")
demoScope.launch {
myBroadcastChannel.openSubscription().consumeEach {
println("subscriber1: $it")
}
}
delay(1000)
myBroadcastChannel.send("2")
delay(1000)
myBroadcastChannel.send("3")
delay(1000)
myBroadcastChannel.send("4")
demoScope.launch {
myBroadcastChannel.openSubscription().consumeEach {
println("subscriber2: $it")
}
}
delay(1000)
myBroadcastChannel.send("5")
/* current output
subscriber1: 1
subscriber1: 2
subscriber1: 3
subscriber1: 4
subscriber2: 4
subscriber2: 5
subscriber1: 5
*/
/* deesired output
subscriber1: 2
subscriber1: 3
subscriber1: 4
subscriber2: 5
subscriber1: 5
*/
octylFractal
11/24/2019, 8:04 AMvalueOrNull
, and if it is non-null, drop the first element from the subscriptionDan Lowe
11/24/2019, 8:18 AMmyBroadcastChannel.openSubscription().apply {
receiveOrNull()
}
in order to get a receive channelDan Lowe
11/24/2019, 8:19 AMDan Lowe
11/24/2019, 8:36 AMreceiveOrNull()
that's preventing further execution.octylFractal
11/24/2019, 8:37 AMreceiveOrNull()
to return if the channel is empty?Dan Lowe
11/24/2019, 8:39 AMoctylFractal
11/24/2019, 8:39 AMDan Lowe
11/24/2019, 8:44 AMpoll
looks like it works. Still waiting on some tests, but the problematic ones have passedDan Lowe
11/24/2019, 8:44 AM