withoutclass
05/23/2018, 3:27 PMforEach wasn't added to the coroutines library for channels? I'm considering putting up a PR to add forEach and forEachIndexed to complement consumeEach and consumeEachIndexed, so that people may avoid the same mistake I made with consumeEachVsevolod Tolstopyatov [JB]
05/23/2018, 3:54 PMforEach, forEach terminates, what next?withoutclass
05/23/2018, 4:01 PMforEach, but I don't want to close the ReceiveChannel when I stop listening/cancel the coroutine job that is consuming the ReceiveChannelwithoutclass
05/23/2018, 4:02 PMconsumeEach with just a for loop like for (element in channel) {}, but I think forEach would read a bit more cleanly.withoutclass
05/23/2018, 4:03 PMRxJava stream, where some events are being published, and I'm only consuming those events from particular points within my android application.withoutclass
05/23/2018, 4:04 PMVsevolod Tolstopyatov [JB]
05/23/2018, 4:17 PMI’m only consuming those events from particular points within my android application.Important note (to be sure you’re aware of this): if you have multiple concurrent
forEach on the same channel, then it’s non-deterministic who will receive specific elements.
E.g. if you have activity, which writes to channel channel and two launched jobs, which invoke channel.forEach, it’s possible situation when one job receives all the elements and other receives none.
BroadcastChannel can be used to avoid such problem.
My activity pauses, so I want to shut down the associated coroutinesIf the activity is paused, not destroyed, is it necessary to shut down coroutines and create them again on resume?
louiscad
05/23/2018, 4:38 PMconsume them without them being closedwithoutclass
05/23/2018, 4:47 PMonResume.
I just see no effective difference between having to write my own for loop or having a forEach defined for convenience sake.
@louiscad I have flip-flopped back and forth over using BroadcastChannel at least for some of my channels, especially from my BT service, though I am a bit unenlightened around how the channel handles new events when the capacity is limited.
Consider that I probably don’t want to allow an unlimited number of BT packets to be queued up on the channel, I want them to be pulled out as soon as they’re read by the appropriate party.withoutclass
05/23/2018, 4:48 PMlouiscad
05/23/2018, 4:49 PMlouiscad
05/23/2018, 4:50 PMwithoutclass
05/23/2018, 4:51 PMlouiscad
05/23/2018, 6:50 PMVsevolod Tolstopyatov [JB]
05/24/2018, 8:48 AMI am a bit unenlightened around how the channel handles new events when the capacity is limited.As a regular channel: it suspends on
send.
I just see no effective difference between having to write my own for loop or having aImagine we have bothdefined for convenience sake.forEach
forEach and consumeEach in kotlinx.coroutines. They look alike, but have different semantics. Sadly, many users don’t read documentation/javadoc carefully, so when they try to consume all elements from the channel, they will pick basically any of these two methods. And it’s not clear, what method should be chosen by default, and it’s not clear (by the name) what is the difference between them.
So we’ve decided to have consumeEach which satisfy 99% of the users and not to add forEach, which, even though it’s useful sometimes, adds additional API ambiguity and is not that usefulwithoutclass
05/24/2018, 2:27 PM