Browse Source

Dry return values.

Roberto Ostinelli 3 years ago
parent
commit
472c8e671b
2 changed files with 19 additions and 13 deletions
  1. 9 6
      src/syn_pg.erl
  2. 10 7
      src/syn_registry.erl

+ 9 - 6
src/syn_pg.erl

@@ -180,7 +180,7 @@ join_or_update(Scope, GroupName, Pid, MetaOrFun) ->
                 {noop, Meta} ->
                     {ok, {Pid, Meta}};
 
-                {{error, Reason}, _} ->
+                {error, Reason} ->
                     {error, Reason};
 
                 {raise, Class, Reason, Stacktrace} ->
@@ -205,8 +205,11 @@ leave(Scope, GroupName, Pid) ->
                     %% return
                     ok;
 
-                {Response, _} ->
-                    Response
+                {ok, _} ->
+                    ok;
+
+                {error, Reason} ->
+                    {error, Reason}
             end
     end.
 
@@ -318,7 +321,7 @@ handle_call({'3.0', join_or_update_on_node, RequesterNode, GroupName, Pid, MetaO
         true ->
             case find_pg_entry_by_name_and_pid(GroupName, Pid, TableByName) of
                 undefined when is_function(MetaOrFun) ->
-                    {reply, {{error, undefined}, undefined}, State};
+                    {reply, {error, undefined}, State};
 
                 undefined ->
                     %% add
@@ -355,7 +358,7 @@ handle_call({'3.0', join_or_update_on_node, RequesterNode, GroupName, Pid, MetaO
             end;
 
         false ->
-            {reply, {{error, not_alive}, undefined}, State}
+            {reply, {error, not_alive}, State}
     end;
 
 handle_call({'3.0', leave_on_node, RequesterNode, GroupName, Pid}, _From, #state{
@@ -365,7 +368,7 @@ handle_call({'3.0', leave_on_node, RequesterNode, GroupName, Pid}, _From, #state
 } = State) ->
     case find_pg_entry_by_name_and_pid(GroupName, Pid, TableByName) of
         undefined ->
-            {reply, {{error, not_in_group}, undefined}, State};
+            {reply, {error, not_in_group}, State};
 
         {{_, _}, Meta, _, _, _} ->
             %% is this the last group process is in?

+ 10 - 7
src/syn_registry.erl

@@ -131,7 +131,7 @@ register_or_update(Scope, Name, Pid, MetaOrFun) ->
                 {noop, Meta} ->
                     {ok, {Pid, Meta}};
 
-                {{error, Reason}, _} ->
+                {error, Reason} ->
                     {error, Reason};
 
                 {raise, Class, Reason, Stacktrace} ->
@@ -162,8 +162,11 @@ unregister(Scope, Name) ->
                             %% return
                             ok;
 
-                        {Response, _} ->
-                            Response
+                        {ok, _} ->
+                            ok;
+
+                        {error, Reason} ->
+                            {error, Reason}
                     end
             end
     end.
@@ -264,11 +267,11 @@ handle_call({'3.0', register_or_update_on_node, RequesterNode, Name, Pid, MetaOr
                     do_register_on_node(Name, Pid, MetaOrFun, MRef, normal, RequesterNode, on_registry_process_updated, State);
 
                 _ ->
-                    {reply, {{error, taken}, undefined}, State}
+                    {reply, {error, taken}, State}
             end;
 
         false ->
-            {reply, {{error, not_alive}, undefined}, State}
+            {reply, {error, not_alive}, State}
     end;
 
 handle_call({'3.0', unregister_on_node, RequesterNode, Name, Pid}, _From, #state{
@@ -278,7 +281,7 @@ handle_call({'3.0', unregister_on_node, RequesterNode, Name, Pid}, _From, #state
 } = State) ->
     case find_registry_entry_by_name(Name, TableByName) of
         undefined ->
-            {reply, {{error, undefined}, undefined}, State};
+            {reply, {error, undefined}, State};
 
         {Name, Pid, Meta, _, _, _} ->
             %% demonitor if the process is not registered under other names
@@ -294,7 +297,7 @@ handle_call({'3.0', unregister_on_node, RequesterNode, Name, Pid}, _From, #state
 
         _ ->
             %% process is registered locally with another pid: race condition, wait for sync to happen & return error
-            {reply, {{error, race_condition}, undefined}, State}
+            {reply, {error, race_condition}, State}
     end;
 
 handle_call(Request, From, #state{scope = Scope} = State) ->