Created
January 16, 2019 12:16
-
-
Save radzserg/4ba5d4b415fe2b23e41bea6a8c9d0e97 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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