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

gotoOla

01/27/2020, 9:45 AM
am I correct in my assumption that channels is at-most-once delivery? E.g. if you have a channel with 5 "processors" that iterates over the channel, none of them will get any duplicates
e

Esa

01/27/2020, 9:48 AM
Yes, that’s what I was told here a few days / a week back. Something about it implementing iterable and making sure every element is only processed once. The experimental function
channel.consumeEach {}
-says so quite explicitly in the name. Each element is consumed by its “processor”, preventing duplicate processing. According to the library it’s currently experimental with planned graduation in 1.4, and it is apparently just an alias for the
for (element in channel)
-syntax.
d

diesieben07

01/27/2020, 9:52 AM
It's not quite an alias.
consumeEach
closes the channel after every element has been received or the receiver throws an exception.
for-in
does not do that.
g

gotoOla

01/27/2020, 10:07 AM
thanks a lot, what you are saying is how I've interpreted it as well...so I guess the documentation is good 😄
r

ribesg

01/27/2020, 10:17 AM
BroadcastChannel
simple smile
😛 1
3 Views