Last active
April 23, 2018 09:43
-
-
Save Slavenin/f78fa3f9531b63d126078f7df9a2779c 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 Behaviours.Telegram do | |
@moduledoc false | |
@callback sendInfo(accountId :: term, info :: term) :: {:ok} | |
end |
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 TelegramModule do | |
@moduledoc false | |
defmacro __using__(opts) do | |
reg = Keyword.get(opts, :reg) | |
quote do | |
@behaviour Behaviours.Telegram | |
def start_link(accountId) do | |
name = via_tuple(accountId) | |
GenServer.start_link(__MODULE__, [accountId], name: name) | |
end | |
defp via_tuple(accountId) do | |
{:via, Registry, {unquote(reg), accountId}} | |
end | |
def sendInfo(accountId, info) do | |
GenServer.cast(via_tuple(accountId), info) | |
end | |
end | |
end | |
end |
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 Start do | |
@moduledoc false | |
use TelegramModule, reg: :process_registry | |
use GenServer | |
def init(_opts) do | |
{:ok, %{}} | |
end | |
def handle_cast(_msg, state) do | |
{:noreply, state} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment