fix(pmap): try not to exit abnormal as much as possible
This commit is contained in:
parent
34fe5e67e7
commit
7824ae5f09
|
@ -473,7 +473,14 @@ do_parallel_map(Fun, List) ->
|
|||
fun(Item) ->
|
||||
erlang:spawn_link(
|
||||
fun() ->
|
||||
Parent ! {self(), Fun(Item)}
|
||||
Res =
|
||||
try
|
||||
{normal, Fun(Item)}
|
||||
catch
|
||||
C:E:St ->
|
||||
{exception, {C, E, St}}
|
||||
end,
|
||||
Parent ! {self(), Res}
|
||||
end
|
||||
)
|
||||
end,
|
||||
|
@ -482,8 +489,10 @@ do_parallel_map(Fun, List) ->
|
|||
lists:foldr(
|
||||
fun(Pid, Acc) ->
|
||||
receive
|
||||
{Pid, Result} ->
|
||||
[Result | Acc]
|
||||
{Pid, {normal, Result}} ->
|
||||
[Result | Acc];
|
||||
{Pid, {exception, {C, E, St}}} ->
|
||||
erlang:raise(C, E, St)
|
||||
end
|
||||
end,
|
||||
[],
|
||||
|
|
|
@ -194,8 +194,8 @@ t_pmap_timeout(_) ->
|
|||
).
|
||||
|
||||
t_pmap_exception(_) ->
|
||||
?assertExit(
|
||||
{foobar, _},
|
||||
?assertError(
|
||||
foobar,
|
||||
emqx_misc:pmap(
|
||||
fun
|
||||
(error) -> error(foobar);
|
||||
|
|
Loading…
Reference in New Issue