when using `produce{}` for a finite sequence of it...
# coroutines
m
when using
produce{}
for a finite sequence of items, the docs say to call
SendChannel.close()
to indicate no more items will be sent. But isn’t the common case for no more items to be sent once
produce
lambda has completed naturally? In which case, why is
SendChannel.close()
not done automatically?
v
It is done automatically:
The channel is [closed][SendChannel.close] when the coroutine completes.
m
ok thanks
Yes, now I see the
ProducerCoroutine.onCompletionInternal()
implementation enforces this.
v
it’s better not to make any conclusions from internal implementation 🙂 All public contracts are usually established in KDoc, unspecified details may change in any release
👍 1
m
Yes, of course, although I find it very informative to see how that is implemented, so it’s beneficial to inspect these things 🙂