From 91514f3ace4cb3a8f36f98f6bcc559bd10749a9e Mon Sep 17 00:00:00 2001 From: Kjell Winblad Date: Tue, 12 Mar 2024 09:12:39 +0100 Subject: [PATCH] refactor: clean up over complicated code This commit cleans up overly complicated code and handles the case when the worker pool is empty. Thank you @thalesmg for suggesting this change. Co-authored-by: Thales Macedo Garitezi --- .../src/emqx_bridge_dynamo_connector.erl | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/apps/emqx_bridge_dynamo/src/emqx_bridge_dynamo_connector.erl b/apps/emqx_bridge_dynamo/src/emqx_bridge_dynamo_connector.erl index 6e2caf1ab..1d29bd427 100644 --- a/apps/emqx_bridge_dynamo/src/emqx_bridge_dynamo_connector.erl +++ b/apps/emqx_bridge_dynamo/src/emqx_bridge_dynamo_connector.erl @@ -198,20 +198,12 @@ on_get_status(_InstanceId, #{pool_name := Pool} = State) -> end. status_result(Results, State) -> - case lists:all(fun(Res) -> Res =:= true end, Results) of - true -> + case lists:filter(fun(Res) -> Res =/= true end, Results) of + [] when Results =:= [] -> + ?status_connecting; + [] -> ?status_connected; - false -> - {value, {false, Error}} = - lists:search( - fun - ({false, _Error}) -> - true; - (_) -> - false - end, - Results - ), + [{false, Error} | _] -> {?status_connecting, State, Error} end.