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

enleur

01/26/2018, 5:11 PM
Copy code
fun <E> ReceiveChannel<E>.onEach(context: CoroutineContext = Unconfined, action: (E) -> Unit): ReceiveChannel<E> =
    produce(context) {
        consumeEach {
            action(it)
            send(it)
        }
    }
r

r4zzz4k

01/26/2018, 5:51 PM
As I mentioned, I already tried
map()
which does the same under the hood. Two things I don't really like about this: 1. I need to pass
capacity
as
map()
creates
produce(capacity = 0)
2. I'm creating several `Channel`s, which are passed as
ReceiveChannel
in one place and
SendChannel
in the other one, so I have to put this
onEach
specifically on
ReceiveChannel
side, which isn't very convenient. So I'll probably stick with derivative class for debugging purposes for now.
4 Views