Scatter / Gather (2 of 4)
- Change the gather function to not care about message order
gather(Pids) when is_list(Pids) ->
gather(length(Pids), []).
gather(0, Results) ->
Results;
gather(Count, Results) ->
receive
{Pid, Item, Result} -> gather(Count-1, [{Item, Result} | Results])
end.
exec_fun(Parent, Fun, Item) ->
Parent ! {self(), Item, catch(Fun(Item))}.