Skip to content

Instantly share code, notes, and snippets.

@haakov
Last active March 5, 2019 14:02
Show Gist options
  • Save haakov/2c6048a4cc4e782bb7df71dd7bab81ff to your computer and use it in GitHub Desktop.
Save haakov/2c6048a4cc4e782bb7df71dd7bab81ff to your computer and use it in GitHub Desktop.
Elixir timer function
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