pdegand
08/31/2018, 3:20 PMreceive()
, some code that will send stuff into the channel is executedbdawg.io
08/31/2018, 7:43 PMval delegateChannel = ConflatedBroadcastChannel<Int>()
suspend fun ConflatedBroadcastChannel<Int>.populate() {
send(10)
}
val subscription = delegateChannel.openSubscription()
val channel = object : ReceiveChannel<Int> by subscription {
private val populated = AtomicBoolean(false)
override suspend fun receive() = this.run {
populate()
subscription.receive()
}
private suspend fun populate() {
if (!populated.get()) {
delegateChannel.populate()
populated.set(true)
}
}
}