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

Mark

11/01/2018, 12:22 PM
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

Vsevolod Tolstopyatov [JB]

11/01/2018, 12:23 PM
It is done automatically:
The channel is [closed][SendChannel.close] when the coroutine completes.
m

Mark

11/01/2018, 12:24 PM
ok thanks
Yes, now I see the
ProducerCoroutine.onCompletionInternal()
implementation enforces this.
v

Vsevolod Tolstopyatov [JB]

11/01/2018, 3:29 PM
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

Mark

11/01/2018, 3:50 PM
Yes, of course, although I find it very informative to see how that is implemented, so it’s beneficial to inspect these things 🙂
2 Views