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) ->
|
fun(Item) ->
|
||||||
erlang:spawn_link(
|
erlang:spawn_link(
|
||||||
fun() ->
|
fun() ->
|
||||||
Parent ! {self(), Fun(Item)}
|
Res =
|
||||||
|
try
|
||||||
|
{normal, Fun(Item)}
|
||||||
|
catch
|
||||||
|
C:E:St ->
|
||||||
|
{exception, {C, E, St}}
|
||||||
|
end,
|
||||||
|
Parent ! {self(), Res}
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
end,
|
end,
|
||||||
|
@ -482,8 +489,10 @@ do_parallel_map(Fun, List) ->
|
||||||
lists:foldr(
|
lists:foldr(
|
||||||
fun(Pid, Acc) ->
|
fun(Pid, Acc) ->
|
||||||
receive
|
receive
|
||||||
{Pid, Result} ->
|
{Pid, {normal, Result}} ->
|
||||||
[Result | Acc]
|
[Result | Acc];
|
||||||
|
{Pid, {exception, {C, E, St}}} ->
|
||||||
|
erlang:raise(C, E, St)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
[],
|
[],
|
||||||
|
|
|
@ -194,8 +194,8 @@ t_pmap_timeout(_) ->
|
||||||
).
|
).
|
||||||
|
|
||||||
t_pmap_exception(_) ->
|
t_pmap_exception(_) ->
|
||||||
?assertExit(
|
?assertError(
|
||||||
{foobar, _},
|
foobar,
|
||||||
emqx_misc:pmap(
|
emqx_misc:pmap(
|
||||||
fun
|
fun
|
||||||
(error) -> error(foobar);
|
(error) -> error(foobar);
|
||||||
|
|
Loading…
Reference in New Issue