ex_ping_server v0.1.0 PingServer

Documentation for PingServer.

A GenServer extension which receives a ping at a regular interval.

Example usage

  defmodule UsePing do
    use PingServer, interval: 10_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 handle_ping(state) do
      # Even though the interval is 10 seconds, we can make it be every 1 second this way
      PingServer.ping_after(self(), 1_000)
      state
    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

Link to this section Summary

Link to this section Functions

Link to this function ping_after(pid, delay \\ 1000)
Link to this function start_link(module, args, opts)