rocketraman
10/23/2018, 5:12 PMSequence
. However, I also want to close the db cursor when the sequence has finished consuming. Is this a valid approach?
suspend fun findSomethings(...): Sequence<Something> {
val cursor = ...
return sequence {
cursor.use {
yieldAll(cursor.iterator())
}
}
}
Dominaezzz
10/23/2018, 7:36 PMSequence
does not fully iterate through it, your cursor will not be closed.Iterable
or Sequence
, you shouldn't tie the lifetime of a resource to one.List<Something>
or (depending on your use case) maybe a ReceiveChannel
since that can be "close"d.