toxara
02/01/2018, 3:05 PMproduce
, and the other using a manual `ConflatedChannel`:
fun View.clicks(): ReceiveChannel<Unit> = produce(bg, capacity = Channel.CONFLATED) {
setOnClickListener { offer(Unit) }
}
fun View.clicks(): ReceiveChannel<Unit> = ConflatedChannel<Unit>().apply {
setOnClickListener { offer(Unit) }
}
First one results in a ClosedSendChannelException: Channel was closed
on every device I've tried it on, while the second one actually works on some devices, while causing an exception on others.
Any idea on what I'm doing wrong?
Common use case is simple routing to another channel:
bg {
someButton.clicks().map { SomeIntent }.consumeEach { intentChannel?.offer(it) }
}
Note: bg
is just an alias for CommonPool
.