Created
February 25, 2016 06:13
-
-
Save s3itz/6f0edd11b9579f704171 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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