Map.put(roles, :callee, %{})
end
- @spec register(binary()) :: Wampex.message()
+ @spec register(procedure :: binary()) :: Wampex.message()
def register(procedure) do
[@register, %{}, procedure]
end
- @spec unregister(integer()) :: Wampex.message()
- def unregister(id) do
- [@unregister, id]
+ @spec unregister(registration_id :: integer()) :: Wampex.message()
+ def unregister(registration_id) do
+ [@unregister, registration_id]
end
- @spec yield(integer()) :: Wampex.message()
+ @spec yield(request_id :: integer()) :: Wampex.message()
def yield(request_id) do
[@yield, request_id, %{}]
end
- @spec yield(integer(), nonempty_list(any())) :: Wampex.message()
+ @spec yield(request_id :: integer(), arg_l :: nonempty_list(any())) :: Wampex.message()
def yield(request_id, arg_l) do
[@yield, request_id, %{}, arg_l]
end
- @spec yield(integer(), nonempty_list(any()), map()) :: Wampex.message()
+ @spec yield(request_id :: integer(), arg_l :: nonempty_list(any()), arg_kw :: map()) ::
+ Wampex.message()
def yield(request_id, arg_l, arg_kw) do
[@yield, request_id, %{}, arg_l, arg_kw]
end
Map.put(roles, :caller, %{})
end
- @spec call(binary()) :: Wampex.message()
+ @spec call(procedure :: binary()) :: Wampex.message()
def call(procedure) do
[@call, %{}, procedure]
end
- @spec call(binary(), nonempty_list(any())) :: Wampex.message()
+ @spec call(procedure :: binary(), arg_l :: nonempty_list(any())) :: Wampex.message()
def call(procedure, arg_l) do
[@call, %{}, procedure, arg_l]
end
- @spec call(binary(), nonempty_list(any()), map()) :: Wampex.message()
+ @spec call(procedure :: binary(), arg_l :: nonempty_list(any()), arg_kw :: map()) ::
+ Wampex.message()
def call(procedure, arg_l, arg_kw) do
[@call, %{}, procedure, arg_l, arg_kw]
end
@impl true
def add(roles), do: roles
- @spec hello(binary(), nonempty_list(module())) :: Wampex.message()
+ @spec hello(realm :: binary(), roles :: nonempty_list(module())) :: Wampex.message()
def hello(realm, roles) do
[@hello, realm, %{roles: Enum.reduce(roles, %{}, fn r, acc -> r.add(acc) end)}]
end
- @spec goodbye(binary()) :: Wampex.message()
+ @spec goodbye(reason :: binary()) :: Wampex.message()
def goodbye(reason) do
[@goodbye, %{}, reason]
end
Map.put(roles, :publisher, %{})
end
- @spec publish(binary()) :: Wampex.message()
+ @spec publish(topic :: binary()) :: Wampex.message()
def publish(topic) do
[@publish, %{}, topic]
end
- @spec publish(binary(), nonempty_list(any())) :: Wampex.message()
+ @spec publish(topic :: binary(), arg_l :: nonempty_list(any())) :: Wampex.message()
def publish(topic, arg_l) do
[@publish, %{}, topic, arg_l]
end
- @spec publish(binary(), nonempty_list(any()), map()) :: Wampex.message()
+ @spec publish(topic :: binary(), arg_l :: nonempty_list(any()), arg_kw :: map()) ::
+ Wampex.message()
def publish(topic, arg_l, arg_kw) do
[@publish, %{}, topic, arg_l, arg_kw]
end
Map.put(roles, :subscriber, %{})
end
- @spec subscribe(binary()) :: Wampex.message()
+ @spec subscribe(topic :: binary()) :: Wampex.message()
def subscribe(topic) do
[@subscribe, %{}, topic]
end
- @spec unsubscribe(integer()) :: Wampex.message()
- def unsubscribe(sub_id) do
- [@unsubscribe, sub_id]
+ @spec unsubscribe(subscription_id :: integer()) :: Wampex.message()
+ def unsubscribe(subscription_id) do
+ [@unsubscribe, subscription_id]
end
@impl true
end
@spec cast_send_request(name :: atom() | pid(), request :: Wampex.message()) :: :ok
- def cast_send_request(p, request) do
- __MODULE__.cast(p, {:send_request, request})
+ def cast_send_request(name, request) do
+ __MODULE__.cast(name, {:send_request, request})
end
@spec send_request(name :: atom() | pid(), request :: Wampex.message(), timeout :: integer()) ::
term()
- def send_request(p, request, timeout) do
- __MODULE__.call(p, {:send_request, request}, timeout)
+ def send_request(name, request, timeout) do
+ __MODULE__.call(name, {:send_request, request}, timeout)
end
defp do_send(r_id, tt, t, request) do
request_id
end
- def get_request_id(current_id) when current_id == @max_id do
+ defp get_request_id(current_id) when current_id == @max_id do
1
end
- def get_request_id(current_id) do
+ defp get_request_id(current_id) do
current_id + 1
end
defmodule Wampex.Transport do
@moduledoc "Behaviour for Transports"
- @callback send_request(atom() | pid(), Wampex.message()) :: :ok
+ @callback send_request(transport :: atom() | pid(), message :: Wampex.message()) :: :ok
@callback start_link(
url: binary(),
session: Wampex.Session.t(),
assert Test.Transport = Wampex.transport_name(Test)
end
- test "get_request_id plus one" do
- assert 11 = Wampex.Session.get_request_id(10)
- end
-
- test "get_request_id resets" do
- assert 1 = Wampex.Session.get_request_id(9_007_199_254_740_992)
- end
-
test "Callee.add" do
assert %{callee: %{}} = Callee.add(%{})
end