worker とか do_times とか
こんな感じかな。
do_times(0, _Fun, _Args) -> ok; do_times(N, Fun, Args) -> apply(Fun, Args), do_times(N - 1, Fun, Args). do_workers(N, Fun, Args) -> do_workers(N, N, Fun, Args). do_workers(Max, 0, _Fun, _Args) -> wait_workers(Max, done), ok; do_workers(Max, N, Fun, Args) -> Self = self(), spawn(fun() -> ok = apply(Fun, Args), Self ! done end), do_workers(Max, N - 1, Fun, Args). wait_workers(0, _Msg) -> ok; wait_workers(N, Msg) -> receive Msg -> [] after ?TIMEOUT-> timout end, wait_workers(N - 1, Msg).