Skip to content

Instantly share code, notes, and snippets.

@edennis
Created October 3, 2016 15:52
Show Gist options
  • Save edennis/a8a736e3b412e61cb636d4f32a538470 to your computer and use it in GitHub Desktop.
Save edennis/a8a736e3b412e61cb636d4f32a538470 to your computer and use it in GitHub Desktop.
rescue/catch from stream?
iex(1)> stream = File.stream!("does_not_exist")
%File.Stream{line_or_bytes: :line, modes: [:raw, :read_ahead, :binary],
path: "does_not_exist", raw: true}
iex(2)> stream |> Enum.take(1)
** (File.Error) could not stream "does_not_exist": no such file or directory
(elixir) lib/file/stream.ex:78: anonymous fn/2 in Enumerable.File.Stream.reduce/3
(elixir) lib/stream.ex:1121: anonymous fn/5 in Stream.resource/3
(elixir) lib/enum.ex:2161: Enum.take/2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment