Created
December 5, 2018 23:32
-
-
Save wstucco/3f3eb42ea93d5c0af9e2e836f7c6924f 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 A do | |
use GenServer | |
def start do | |
GenServer.start_link(__MODULE__, []) | |
end | |
def send_after(pid) do | |
1..10 | |
|> Enum.each(fn _ -> Process.send_after(pid, :message, 1_000) end) | |
end | |
def apply_after do | |
1..10 | |
|> Enum.each(fn _ -> :timer.apply_after(1_000, __MODULE__, :message, [System.monotonic_time(:millisecond)]) end) | |
end | |
def init(_args) do | |
{:ok, System.monotonic_time(:millisecond)} | |
end | |
def handle_info(:message, state) do | |
Process.sleep(2_000) | |
IO.inspect({:message, (System.monotonic_time(:millisecond) - state)}) | |
{:noreply, System.monotonic_time(:millisecond)} | |
end | |
def message(time) do | |
Process.sleep(2_000) | |
IO.inspect({:message, (System.monotonic_time(:millisecond) - time)}) | |
end | |
end | |
{:ok, pid} = A.start() | |
A.send_after(pid) | |
A.apply_after() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment