-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Close Files.lines stream #14379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Close Files.lines stream #14379
Conversation
Tested locally a few times without hitting the issue in #14376. |
files.flatMap(path => toolArgsParse { | ||
val stream = Files.lines(path, charset) | ||
try stream.limit(10).toScala(List) | ||
finally stream.close() | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We normally use scala.util.Using for this:
files.flatMap(path => toolArgsParse { | |
val stream = Files.lines(path, charset) | |
try stream.limit(10).toScala(List) | |
finally stream.close() | |
}) | |
files.flatMap(path => toolArgsParse(Using(Files.lines(path, charset))(_.limit(10).toScala(List)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed "toScala(List)" were just as much as "terminal operation" as toArray
is on j.u.s.Stream. Almost feel like it's a bug that it isn't.
Sorry for the bug.
Oh, nvm, terminal doesn't mean close apparently. https://stackoverflow.com/a/27382060/463761 |
Fixes #14376