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

Patrick Ramsey

08/25/2021, 1:58 AM
Question --- Channel.consumeEach() (a suspend function) seems to be implemented internally as
for (e in this) action(e)
— which looks like it’s implicitly calling this.iterator() and iterating over the channel that way. I assume that can’t actually be what’s happening (right?) since Iterator.next() is blocking. Or does Channel.consumeEach() actually block?
answer: whoa. ChannelIterator.hasNext() is a suspend function. I didn’t know you could do that.
wowee.
c

CLOVIS

08/25/2021, 10:44 AM
Yep, they have a specific Iterator that can suspend to enable these syntaxes
4 Views