Marc Knaup
03/21/2019, 3:35 PMbreak
at some point?streetsofboston
03/21/2019, 3:39 PMMarc Knaup
03/21/2019, 3:39 PMstreetsofboston
03/21/2019, 3:43 PMlaunch
and tie the CoroutineScope of the launch
to closing the channel by implementing the Job.invokeOnCompletion
on the job returned by the call to launch
. Close the channel in the invokeOnCompletion.
Then this Channel could be given to the consumer as a ReceiveChannelMarc Knaup
03/21/2019, 3:52 PMMongoIterable
a ReceiveChannel
which doesn't make sense I guess 🙄streetsofboston
03/21/2019, 3:59 PMuse
function to mimic that behavior somewhere as long as you make your new iterable ‘closeable’ as well.use
, the channel won’t be closed…..Marc Knaup
03/21/2019, 4:01 PMstreetsofboston
03/21/2019, 4:11 PMsomeChannel.consume { val channel = this }
on your channel first as well. consume
makes sure its receiver Channel is closed(canceled) when your code returns from the consume
call.Marc Knaup
03/21/2019, 4:13 PMstreetsofboston
03/21/2019, 4:43 PMbreak
statement doesn’t do that. This would mean that whichever solution you create, the user of the channel has to do something extra somewhere to properly close the channel.
You could have the creator of the Channel close the channel when it is done with it or when the creator goes out of (Coroutine)scope. But that may not work for you use-cases….r4zzz4k
03/21/2019, 4:57 PMMarc Knaup
03/21/2019, 5:13 PMsuspend
added. You don't need to change anything else.
But that's not possible without leaking channels or having potentially unexpected channel lifetimes (timeout, scoped, etc.).streetsofboston
03/21/2019, 5:17 PMMarc Knaup
03/21/2019, 5:59 PM