Esa
01/17/2020, 2:55 PMCoroutineScope.produce(), ReceiveChannel<E>.consumeEach{} and ProducerScope.send()? Is there any way to know? I’ve got a working implementation now, but knowing that it may break without warning is a bit scary. Also, is this the wrong place to ask this question?
Is the discussion boards a better place?Evan R.
01/17/2020, 3:23 PMCoroutineScope.produce() -> define a channel and do a launch { } to write values to the channel
• ReceiveChannel<E>.consumeEach{} -> for (value in channel)
• ProducerScope.send() -> channel.send() in the launch { } block mentioned aboveEvan R.
01/17/2020, 3:23 PMlaunch { } because then you can produce values to multiple channels at onceEvan R.
01/17/2020, 3:25 PMcoroutinescope.produce() is stable but the API may be subject to change. That’s all the @ExperimentalCoroutinesApi annotation meansEsa
01/17/2020, 3:44 PMconsumeEach because it is important that each element is processed only once - the for loop may see some elements be processed by different workers, no?Esa
01/17/2020, 4:23 PMrepeat(10) { launch { channel.consumeEach { // logic } } }, so any substitute that ensures each launch gets a unique element is goodtseisel
01/18/2020, 8:41 AMconsumeEach is just an alias of the for loop.Esa
01/20/2020, 7:33 AMrepeat(n)-workers to iterate it?
Not that I doubt you at all, it’s just I don’t see how this is safe when processing only once is important. Enlighten me please 🙂tseisel
01/20/2020, 9:02 AMEsa
01/20/2020, 9:19 AMEvan R.
01/20/2020, 1:43 PMBroadcastChannelEvan R.
01/20/2020, 1:44 PMIterable by just repeatedly calling receive() and so even if you’re using a for loop you’d still receive data the same way