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

Chachako

06/23/2022, 9:39 AM
Hi everyone, I would like to know when the hang of
channelFlow.collect
will resume? If there is a task in the
channelFlow
block that doesn’t know when it will complete, when will the coroutines channel close? I’m a little curious what the criteria is for the channel to determine
channelFlow
completion, is it to wait a while without any
send
and then end the hang?
s
c

Chachako

06/23/2022, 9:52 AM
@Sam Thank you, but I also want to understand how
channelFlow
resume works hahaha
s

Sam

06/23/2022, 9:55 AM
Without
awaitClose
, the flow will terminate as soon as the code inside the builder is done executing. With
awaitClose
, it will run forever, until you explicitly stop collecting it. If you want anything different from those two options, you would need to implement it manually by calling
close()
on the channel inside the builder.
❤️ 1
c

Chachako

06/23/2022, 9:58 AM
This completely answered my questions!
s

Sam

06/23/2022, 9:58 AM
In your Gradle example,
configureEach
just registers a callback that will be invoked "as each element is required", so it's likely that the flow would complete immediately, before the callback has been invoked on any of the items.