diff --git a/src/minirest_util.erl b/src/minirest_util.erl index 0c39ac9..16dcc6c 100644 --- a/src/minirest_util.erl +++ b/src/minirest_util.erl @@ -37,7 +37,7 @@ pmap_exec(CallerPid, Fun, El, Timeout) -> ExecResult = receive {result, Pid, {normal, Result}} -> Result; - {result, Pid, {crash, {C, E, ST}}} -> erlang:raise(C, E, ST); + {result, Pid, {crash, {C, E, ST}}} -> {error, {El, {C, E, ST}}}; {'DOWN', Ref, process, Pid, Reason} -> {error, {El, Reason}} after Timeout -> true = erlang:exit(Pid, kill), diff --git a/test/minirest_util_SUITE.erl b/test/minirest_util_SUITE.erl new file mode 100644 index 0000000..1a2b385 --- /dev/null +++ b/test/minirest_util_SUITE.erl @@ -0,0 +1,38 @@ +%% Copyright (c) 2013-2023 EMQ Technologies Co., Ltd. All Rights Reserved. +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. + +-module(minirest_util_SUITE). + +-compile(export_all). +-compile(nowarn_export_all). + +-include_lib("stdlib/include/assert.hrl"). + +all() -> + [ + t_pmap_exception + ]. + +t_pmap_exception(_Config) -> + process_flag(trap_exit, true), + ct:timetrap({seconds, 2}), + + ?assertMatch( + [ + {error, {a, {error, a, _}}}, + {error, {b, {error, b, _}}}, + {error, {c, {error, c, _}}} + ], + minirest_util:pmap(fun(X) -> error(X) end, [a, b, c], 1000) + ).