Last active
March 5, 2019 14:02
-
-
Save haakov/2c6048a4cc4e782bb7df71dd7bab81ff to your computer and use it in GitHub Desktop.
Elixir timer function
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 Elevator.Timer do | |
def keepalive_timer(parent, id, msecs) do | |
receive do | |
:keepalive -> | |
keepalive_timer(parent, id, msecs) | |
after | |
msecs -> | |
send(parent, {:timeout, id}) | |
end | |
end | |
end | |
#To run: | |
# this_pid = self | |
# spawn fn -> Elevator.Timer.keepalive_timer(this_pid, 1, 5000) end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment