feat(emqx_utils): add pforeach/2,3
This commit is contained in:
parent
a6568dec75
commit
d3a6870097
|
@ -51,6 +51,8 @@
|
||||||
gen_id/0,
|
gen_id/0,
|
||||||
gen_id/1,
|
gen_id/1,
|
||||||
explain_posix/1,
|
explain_posix/1,
|
||||||
|
pforeach/2,
|
||||||
|
pforeach/3,
|
||||||
pmap/2,
|
pmap/2,
|
||||||
pmap/3,
|
pmap/3,
|
||||||
readable_error_msg/1,
|
readable_error_msg/1,
|
||||||
|
@ -423,6 +425,15 @@ explain_posix(estale) -> "Stale remote file handle";
|
||||||
explain_posix(exdev) -> "Cross-domain link";
|
explain_posix(exdev) -> "Cross-domain link";
|
||||||
explain_posix(NotPosix) -> NotPosix.
|
explain_posix(NotPosix) -> NotPosix.
|
||||||
|
|
||||||
|
-spec pforeach(fun((A) -> term()), list(A)) -> ok.
|
||||||
|
pforeach(Fun, List) when is_function(Fun, 1), is_list(List) ->
|
||||||
|
pforeach(Fun, List, ?DEFAULT_PMAP_TIMEOUT).
|
||||||
|
|
||||||
|
-spec pforeach(fun((A) -> term()), list(A), timeout()) -> ok.
|
||||||
|
pforeach(Fun, List, Timeout) ->
|
||||||
|
_ = pmap(Fun, List, Timeout),
|
||||||
|
ok.
|
||||||
|
|
||||||
%% @doc Like lists:map/2, only the callback function is evaluated
|
%% @doc Like lists:map/2, only the callback function is evaluated
|
||||||
%% concurrently.
|
%% concurrently.
|
||||||
-spec pmap(fun((A) -> B), list(A)) -> list(B).
|
-spec pmap(fun((A) -> B), list(A)) -> list(B).
|
||||||
|
|
Loading…
Reference in New Issue