https://kotlinlang.org logo
#coroutines
Title
# coroutines
l

louiscad

07/05/2018, 8:46 AM
Also, is there any alternative?
e

elizarov

07/05/2018, 6:24 PM
Copy code
fun <T> ReceiveChannel<T>.onEach(block: (T) -> Unit): ReceiveChannel<T> =
    produce(onCompletion = consumes()) {
        for (it in this@onEach) {
            block(it)
            send(it)
        }
    }
l

louiscad

07/05/2018, 6:27 PM
That doesn't explain my previous question: Why it's not there? Should I submit a PR?
e

elizarov

07/05/2018, 6:44 PM
TooManyChannelsException. We’d like to redo all existing operators via cold streams first, then go on to expand repertoire of operators.
It’s kind of a waste to simply move elements between two channels, all for the pleasure of peeking at them via
onEach
.
l

louiscad

07/05/2018, 9:00 PM
I see. My small use case was scanning for a Bluetooth Low Energy device, expecting only one close by, and showing meaningful errors if it's not close enough, or more than one device is close. It was so complex adding a few other requirements that I finally gave up doing the complex filtering while the channel is receiving values, and just cancel the channel after a short duration, to then work on a list. I'll see if I can improve it to fail faster by using the new
broadcast()
function, and having one subscription channel per requirement.
2 Views