Current section
Files
Jump to
Current section
Files
lib/user.ex
defmodule UsePing do
use PingServer, interval: 1_000
def start_link(thing) do
# You can start link this way. It will call PingServer.init(thing)
PingServer.start_link(__MODULE__, thing, [])
end
def init(sdf) do
PingServer.init(self())
{:ok, sdf}
end
def handle_ping(state) do
IO.inspect(state)
# Even though the interval is 10 seconds, we can make it be every 1 second this way
PingServer.ping_after(self(), 1_000)
end
def handle_info(:manual_ping, state) do
# only one ping will happen but it will happen pretty much right away.
PingServer.ping(self())
PingServer.ping(self())
PingServer.ping(self())
{:noreply, state}
end
end