Skip to content

Instantly share code, notes, and snippets.

@Jeweller-Tsai
Last active June 18, 2016 04:06
Show Gist options
  • Save Jeweller-Tsai/dfa5b24db564d12623a03555b3d23cac to your computer and use it in GitHub Desktop.
Save Jeweller-Tsai/dfa5b24db564d12623a03555b3d23cac to your computer and use it in GitHub Desktop.
defmodule ElixirTail do
def tail path do
Stream.resource(fn -> File.open!(path) end,
fn file ->
case IO.read(file, :line) do
:eof ->
:timer.sleep 10
{[], file}
data ->
IO.write data
{[data], file}
end
end,
fn file -> File.close(file) end)
|> Stream.run
end
end
@Jeweller-Tsai
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment