Skip to content

Instantly share code, notes, and snippets.

@radzserg
Created January 16, 2019 12:16
Show Gist options
  • Select an option

  • Save radzserg/4ba5d4b415fe2b23e41bea6a8c9d0e97 to your computer and use it in GitHub Desktop.

Select an option

Save radzserg/4ba5d4b415fe2b23e41bea6a8c9d0e97 to your computer and use it in GitHub Desktop.
defmodule Rsed.EventDispatcher do
defmacro __using__(opts) do
name = Keyword.get(opts, :name)
quote do
use GenServer
# rest of our functions
defp my_name() do
unquote(name)
end
def init(:ok) do
# if there's configure function, call it and set initial state
listeners = if Keyword.has_key?(__MODULE__.__info__(:functions), :configure) do
apply(__MODULE__, :configure, [])
else
%{}
end
{:ok, listeners}
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment