Skip to content

Instantly share code, notes, and snippets.

@haakov
Last active March 5, 2019 14:02
Show Gist options
  • Select an option

  • Save haakov/2c6048a4cc4e782bb7df71dd7bab81ff to your computer and use it in GitHub Desktop.

Select an option

Save haakov/2c6048a4cc4e782bb7df71dd7bab81ff to your computer and use it in GitHub Desktop.

Revisions

  1. haakov revised this gist Mar 5, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion keepalive_timer.ex
    Original file line number Diff line number Diff line change
    @@ -13,4 +13,4 @@ end

    #To run:
    # this_pid = self
    # Elevator.Timer.keepalive_timer(this_pid, 1, 5000)
    # spawn fn -> Elevator.Timer.keepalive_timer(this_pid, 1, 5000) end
  2. haakov revised this gist Mar 5, 2019. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions keepalive_timer.ex
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,6 @@ defmodule Elevator.Timer do
    end
    end

    To run:
    this_pid = self
    Elevator.Timer.keepalive_timer(this_pid, 1, 5000)
    #To run:
    # this_pid = self
    # Elevator.Timer.keepalive_timer(this_pid, 1, 5000)
  3. haakov created this gist Mar 5, 2019.
    17 changes: 17 additions & 0 deletions keepalive_timer.ex
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    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
    Elevator.Timer.keepalive_timer(this_pid, 1, 5000)