Skip to content

Instantly share code, notes, and snippets.

@s3itz
Created February 25, 2016 06:13
Show Gist options
  • Save s3itz/6f0edd11b9579f704171 to your computer and use it in GitHub Desktop.
Save s3itz/6f0edd11b9579f704171 to your computer and use it in GitHub Desktop.
defmodule Countdown do
def sleep(seconds) do
receive do
after seconds*1000 -> nil
end
end
def say(text) do
spawn fn -> :os.cmd('say #{text}') end
end
def timer do
Stream.resource(
fn ->
{_h, _m, s} = :erlang.time
60 - s - 1
end,
fn
0 ->
{:halt, 0}
count ->
sleep(1)
{ [inspect(count)], count - 1}
end,
fn _ -> end
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment