Просмотр исходного кода

Keep term() vs any() consistency in specs.

Roberto Ostinelli 3 лет назад
Родитель
Сommit
905a10dca2
4 измененных файлов с 47 добавлено и 47 удалено
  1. 18 18
      src/syn.erl
  2. 11 11
      src/syn.hrl
  3. 3 3
      src/syn_app.erl
  4. 15 15
      src/syn_backbone.erl

+ 18 - 18
src/syn.erl

@@ -168,7 +168,7 @@ start() ->
     ok.
 
 %% @doc Stops Syn manually.
--spec stop() -> ok | {error, Reason :: any()}.
+-spec stop() -> ok | {error, Reason :: term()}.
 stop() ->
     application:stop(syn).
 
@@ -272,13 +272,13 @@ set_event_handler(Module) ->
 %% 2> syn:lookup(devices, "SN-123-456789").
 %% {<0.79.0>, undefined}
 %% '''
--spec lookup(Scope :: atom(), Name :: any()) -> {pid(), Meta :: any()} | undefined.
+-spec lookup(Scope :: atom(), Name :: term()) -> {pid(), Meta :: term()} | undefined.
 lookup(Scope, Name) ->
     syn_registry:lookup(Scope, Name).
 
 %% @equiv register(Scope, Name, Pid, undefined)
 %% @end
--spec register(Scope :: atom(), Name :: any(), Pid :: any()) -> ok | {error, Reason :: any()}.
+-spec register(Scope :: atom(), Name :: term(), Pid :: term()) -> ok | {error, Reason :: term()}.
 register(Scope, Name, Pid) ->
     register(Scope, Name, Pid, undefined).
 
@@ -338,7 +338,7 @@ register(Scope, Name, Pid) ->
 %% 3> gen_server:call(Tuple, your_message).
 %% your_message
 %% '''
--spec register(Scope :: atom(), Name :: any(), Pid :: pid(), Meta :: any()) -> ok | {error, Reason :: any()}.
+-spec register(Scope :: atom(), Name :: term(), Pid :: pid(), Meta :: term()) -> ok | {error, Reason :: term()}.
 register(Scope, Name, Pid, Meta) ->
     syn_registry:register(Scope, Name, Pid, Meta).
 
@@ -353,7 +353,7 @@ register(Scope, Name, Pid, Meta) ->
 %%
 %% You don't need to unregister names of processes that are about to die, since they are monitored by Syn
 %% and they will be removed automatically.
--spec unregister(Scope :: atom(), Name :: any()) -> ok | {error, Reason :: any()}.
+-spec unregister(Scope :: atom(), Name :: term()) -> ok | {error, Reason :: term()}.
 unregister(Scope, Name) ->
     syn_registry:unregister(Scope, Name).
 
@@ -386,28 +386,28 @@ local_registry_count(Scope) ->
     registry_count(Scope, node()).
 
 %% ----- \/ gen_server via module interface --------------------------
--spec register_name(Name :: any(), Pid :: pid()) -> yes | no.
+-spec register_name(Name :: term(), Pid :: pid()) -> yes | no.
 register_name({Scope, Name}, Pid) ->
     case register(Scope, Name, Pid) of
         ok -> yes;
         _ -> no
     end.
 
--spec unregister_name(Name :: any()) -> any().
+-spec unregister_name(Name :: term()) -> term().
 unregister_name({Scope, Name}) ->
     case unregister(Scope, Name) of
         ok -> Name;
         _ -> nil
     end.
 
--spec whereis_name(Name :: any()) -> pid() | undefined.
+-spec whereis_name(Name :: term()) -> pid() | undefined.
 whereis_name({Scope, Name}) ->
     case lookup(Scope, Name) of
         {Pid, _Meta} -> Pid;
         undefined -> undefined
     end.
 
--spec send(Name :: any(), Message :: any()) -> pid().
+-spec send(Name :: term(), Message :: term()) -> pid().
 send({Scope, Name}, Message) ->
     case whereis_name({Scope, Name}) of
         undefined ->
@@ -440,7 +440,7 @@ members(Scope, GroupName) ->
     syn_pg:members(Scope, GroupName).
 
 %% @doc Returns whether a `pid()' is a member of GroupName in the specified `Scope'.
--spec is_member(Scope :: atom(), GroupName :: any(), Pid :: pid()) -> boolean().
+-spec is_member(Scope :: atom(), GroupName :: term(), Pid :: pid()) -> boolean().
 is_member(Scope, GroupName, Pid) ->
     syn_pg:is_member(Scope, GroupName, Pid).
 
@@ -450,13 +450,13 @@ local_members(Scope, GroupName) ->
     syn_pg:local_members(Scope, GroupName).
 
 %% @doc Returns whether a `pid()' is a member of GroupName in the specified `Scope' running on the local node.
--spec is_local_member(Scope :: atom(), GroupName :: any(), Pid :: pid()) -> boolean().
+-spec is_local_member(Scope :: atom(), GroupName :: term(), Pid :: pid()) -> boolean().
 is_local_member(Scope, GroupName, Pid) ->
     syn_pg:is_local_member(Scope, GroupName, Pid).
 
 %% @equiv join(Scope, GroupName, Pid, undefined)
 %% @end
--spec join(Scope :: any(), Name :: any(), Pid :: any()) -> ok | {error, Reason :: any()}.
+-spec join(Scope :: term(), Name :: term(), Pid :: term()) -> ok | {error, Reason :: term()}.
 join(Scope, GroupName, Pid) ->
     join(Scope, GroupName, Pid, undefined).
 
@@ -482,7 +482,7 @@ join(Scope, GroupName, Pid) ->
 %% 1> syn:join(devices, "area-1", self(), [{meta, one}]).
 %% ok
 %% '''
--spec join(Scope :: atom(), GroupName :: any(), Pid :: pid(), Meta :: any()) -> ok | {error, Reason :: any()}.
+-spec join(Scope :: atom(), GroupName :: term(), Pid :: pid(), Meta :: term()) -> ok | {error, Reason :: term()}.
 join(Scope, GroupName, Pid, Meta) ->
     syn_pg:join(Scope, GroupName, Pid, Meta).
 
@@ -495,7 +495,7 @@ join(Scope, GroupName, Pid, Meta) ->
 %%
 %% You don't need to remove processes that are about to die, since they are monitored by Syn and they will be removed
 %% automatically from their groups.
--spec leave(Scope :: atom(), GroupName :: any(), Pid :: pid()) -> ok | {error, Reason :: any()}.
+-spec leave(Scope :: atom(), GroupName :: term(), Pid :: pid()) -> ok | {error, Reason :: term()}.
 leave(Scope, GroupName, Pid) ->
     syn_pg:leave(Scope, GroupName, Pid).
 
@@ -584,20 +584,20 @@ local_group_names(Scope) ->
 %% Shell got my_message
 %% ok
 %% '''
--spec publish(Scope :: atom(), GroupName :: any(), Message :: any()) -> {ok, RecipientCount :: non_neg_integer()}.
+-spec publish(Scope :: atom(), GroupName :: term(), Message :: term()) -> {ok, RecipientCount :: non_neg_integer()}.
 publish(Scope, GroupName, Message) ->
     syn_pg:publish(Scope, GroupName, Message).
 
 %% @doc Publish a message to all group members running on the local node in the specified `Scope'.
 %%
 %% Works similarly to {@link publish/3} for local processes.
--spec local_publish(Scope :: atom(), GroupName :: any(), Message :: any()) -> {ok, RecipientCount :: non_neg_integer()}.
+-spec local_publish(Scope :: atom(), GroupName :: term(), Message :: term()) -> {ok, RecipientCount :: non_neg_integer()}.
 local_publish(Scope, GroupName, Message) ->
     syn_pg:local_publish(Scope, GroupName, Message).
 
 %% @equiv multi_call(Scope, GroupName, Message, 5000)
 %% @end
--spec multi_call(Scope :: atom(), GroupName :: any(), Message :: any()) ->
+-spec multi_call(Scope :: atom(), GroupName :: term(), Message :: term()) ->
     {
         Replies :: [{{pid(), Meta :: term()}, Reply :: term()}],
         BadReplies :: [{pid(), Meta :: term()}]
@@ -616,7 +616,7 @@ multi_call(Scope, GroupName, Message) ->
 %% Syn will wait up to the value specified in `Timeout' to receive all replies from the members.
 %% The responses will be added to the `Replies' list, while the members that do not reply in time or that crash
 %% before sending a reply will be added to the `BadReplies' list.
--spec multi_call(Scope :: atom(), GroupName :: any(), Message :: any(), Timeout :: non_neg_integer()) ->
+-spec multi_call(Scope :: atom(), GroupName :: term(), Message :: term(), Timeout :: non_neg_integer()) ->
     {
         Replies :: [{{pid(), Meta :: term()}, Reply :: term()}],
         BadReplies :: [{pid(), Meta :: term()}]

+ 11 - 11
src/syn.hrl

@@ -29,48 +29,48 @@
     Version :: atom()
 }.
 -type syn_registry_entry() :: {
-    Name :: any(),
+    Name :: term(),
     Pid :: pid(),
-    Meta :: any(),
+    Meta :: term(),
     Time :: integer(),
     MRef :: undefined | reference(),
     Node :: node()
 }.
 -type syn_registry_entry_by_pid() :: {
     Pid :: pid(),
-    Name :: any(),
-    Meta :: any(),
+    Name :: term(),
+    Meta :: term(),
     Time :: integer(),
     MRef :: undefined | reference(),
     Node :: node()
 }.
 -type syn_registry_tuple() :: {
-    Name :: any(),
+    Name :: term(),
     Pid :: pid(),
-    Meta :: any(),
+    Meta :: term(),
     Time :: integer()
 }.
 -type syn_pg_entry() :: {
     {
-        GroupName :: any(),
+        GroupName :: term(),
         Pid :: pid()
     },
-    Meta :: any(),
+    Meta :: term(),
     Time :: integer(),
     MRef :: undefined | reference(),
     Node :: node()
 }.
 -type syn_pg_tuple() :: {
-    GroupName :: any(),
+    GroupName :: term(),
     Pid :: pid(),
-    Meta :: any(),
+    Meta :: term(),
     Time :: non_neg_integer()
 }.
 
 %% records
 -record(state, {
     handler = undefined :: undefined | module(),
-    handler_state = undefined :: any(),
+    handler_state = undefined :: term(),
     scope = undefined :: atom(),
     process_name :: atom(),
     nodes_map = #{} :: #{node() => pid()},

+ 3 - 3
src/syn_app.erl

@@ -34,14 +34,14 @@
 %% ===================================================================
 -spec start(
     StartType :: normal | {takeover, node()} | {failover, node()},
-    StartArgs :: any()
-) -> {ok, pid()} | {ok, pid(), State :: any()} | {error, any()}.
+    StartArgs :: term()
+) -> {ok, pid()} | {ok, pid(), State :: term()} | {error, term()}.
 start(_StartType, _StartArgs) ->
     %% ensure event handler is loaded
     syn_event_handler:ensure_event_handler_loaded(),
     %% start main sup
     syn_sup:start_link().
 
--spec stop(State :: any()) -> ok.
+-spec stop(State :: term()) -> ok.
 stop(_State) ->
     ok.

+ 15 - 15
src/syn_backbone.erl

@@ -41,7 +41,7 @@
 %% ===================================================================
 %% API
 %% ===================================================================
--spec start_link() -> {ok, pid()} | {error, any()}.
+-spec start_link() -> {ok, pid()} | {error, term()}.
 start_link() ->
     Options = [],
     gen_server:start_link({local, ?MODULE}, ?MODULE, [], Options).
@@ -50,11 +50,11 @@ start_link() ->
 create_tables_for_scope(Scope) ->
     gen_server:call(?MODULE, {create_tables_for_scope, Scope}).
 
--spec save_process_name(Key :: any(), ProcessName :: atom()) -> true.
+-spec save_process_name(Key :: term(), ProcessName :: atom()) -> true.
 save_process_name(Key, ProcessName) ->
     true = ets:insert(syn_process_names, {Key, ProcessName}).
 
--spec get_process_name(Key :: any()) -> ProcessName :: atom().
+-spec get_process_name(Key :: term()) -> ProcessName :: atom().
 get_process_name(Key) ->
     case ets:lookup(syn_process_names, Key) of
         [{_, ProcessName}] -> ProcessName;
@@ -79,7 +79,7 @@ get_table_name(TableId, Scope) ->
     {ok, State :: map()} |
     {ok, State :: map(), Timeout :: non_neg_integer()} |
     ignore |
-    {stop, Reason :: any()}.
+    {stop, Reason :: term()}.
 init([]) ->
     %% create table names table
     ets:new(syn_table_names, [set, public, named_table, {read_concurrency, true}, {decentralized_counters, true}]),
@@ -90,13 +90,13 @@ init([]) ->
 %% ----------------------------------------------------------------------------------------------------------
 %% Call messages
 %% ----------------------------------------------------------------------------------------------------------
--spec handle_call(Request :: any(), From :: any(), State :: map()) ->
-    {reply, Reply :: any(), State :: map()} |
-    {reply, Reply :: any(), State :: map(), Timeout :: non_neg_integer()} |
+-spec handle_call(Request :: term(), From :: term(), State :: map()) ->
+    {reply, Reply :: term(), State :: map()} |
+    {reply, Reply :: term(), State :: map(), Timeout :: non_neg_integer()} |
     {noreply, State :: map()} |
     {noreply, State :: map(), Timeout :: non_neg_integer()} |
-    {stop, Reason :: any(), Reply :: any(), State :: map()} |
-    {stop, Reason :: any(), State :: map()}.
+    {stop, Reason :: term(), Reply :: term(), State :: map()} |
+    {stop, Reason :: term(), State :: map()}.
 handle_call({create_tables_for_scope, Scope}, _From, State) ->
     error_logger:info_msg("SYN[~s] Creating tables for scope '~s'", [?MODULE, Scope]),
     ensure_table_existence(set, syn_registry_by_name, Scope),
@@ -112,10 +112,10 @@ handle_call(Request, From, State) ->
 %% ----------------------------------------------------------------------------------------------------------
 %% Cast messages
 %% ----------------------------------------------------------------------------------------------------------
--spec handle_cast(Msg :: any(), State :: map()) ->
+-spec handle_cast(Msg :: term(), State :: map()) ->
     {noreply, State :: map()} |
     {noreply, State :: map(), Timeout :: non_neg_integer()} |
-    {stop, Reason :: any(), State :: map()}.
+    {stop, Reason :: term(), State :: map()}.
 handle_cast(Msg, State) ->
     error_logger:warning_msg("SYN[~s] Received an unknown cast message: ~p", [?MODULE, Msg]),
     {noreply, State}.
@@ -123,10 +123,10 @@ handle_cast(Msg, State) ->
 %% ----------------------------------------------------------------------------------------------------------
 %% All non Call / Cast messages
 %% ----------------------------------------------------------------------------------------------------------
--spec handle_info(Info :: any(), State :: map()) ->
+-spec handle_info(Info :: term(), State :: map()) ->
     {noreply, State :: map()} |
     {noreply, State :: map(), Timeout :: non_neg_integer()} |
-    {stop, Reason :: any(), State :: map()}.
+    {stop, Reason :: term(), State :: map()}.
 handle_info(Info, State) ->
     error_logger:warning_msg("SYN[~s] Received an unknown info message: ~p", [?MODULE, Info]),
     {noreply, State}.
@@ -134,7 +134,7 @@ handle_info(Info, State) ->
 %% ----------------------------------------------------------------------------------------------------------
 %% Terminate
 %% ----------------------------------------------------------------------------------------------------------
--spec terminate(Reason :: any(), State :: map()) -> terminated.
+-spec terminate(Reason :: term(), State :: map()) -> terminated.
 terminate(Reason, _State) ->
     error_logger:info_msg("SYN[~s] Terminating with reason: ~p", [?MODULE, Reason]),
     %% return
@@ -143,7 +143,7 @@ terminate(Reason, _State) ->
 %% ----------------------------------------------------------------------------------------------------------
 %% Convert process state when code is changed.
 %% ----------------------------------------------------------------------------------------------------------
--spec code_change(OldVsn :: any(), State :: map(), Extra :: any()) -> {ok, State :: map()}.
+-spec code_change(OldVsn :: term(), State :: map(), Extra :: term()) -> {ok, State :: map()}.
 code_change(_OldVsn, State, _Extra) ->
     {ok, State}.