Przeglądaj źródła

Merge pull request #13467 from ieQu1/dev/optimize-connection-process_msg

fix(connection): Make process_msg function tail-recursive
ieQu1 1 rok temu
rodzic
commit
706cab3c86
1 zmienionych plików z 11 dodań i 13 usunięć
  1. 11 13
      apps/emqx/src/emqx_connection.erl

+ 11 - 13
apps/emqx/src/emqx_connection.erl

@@ -468,19 +468,17 @@ cancel_stats_timer(State) ->
 process_msg([], State) ->
     {ok, State};
 process_msg([Msg | More], State) ->
-    try
-        case handle_msg(Msg, State) of
-            ok ->
-                process_msg(More, State);
-            {ok, NState} ->
-                process_msg(More, NState);
-            {ok, Msgs, NState} ->
-                process_msg(append_msg(More, Msgs), NState);
-            {stop, Reason, NState} ->
-                {stop, Reason, NState};
-            {stop, Reason} ->
-                {stop, Reason, State}
-        end
+    try handle_msg(Msg, State) of
+        ok ->
+            process_msg(More, State);
+        {ok, NState} ->
+            process_msg(More, NState);
+        {ok, Msgs, NState} ->
+            process_msg(append_msg(More, Msgs), NState);
+        {stop, Reason, NState} ->
+            {stop, Reason, NState};
+        {stop, Reason} ->
+            {stop, Reason, State}
     catch
         exit:normal ->
             {stop, normal, State};