Skip to content

Instantly share code, notes, and snippets.

@abolibibelot
Created May 16, 2013 08:42
Show Gist options
  • Save abolibibelot/5590316 to your computer and use it in GitHub Desktop.
Save abolibibelot/5590316 to your computer and use it in GitHub Desktop.
pmap(Mapper,XS,_) when length(XS) =< 2-> %async not really useful here
[Mapper(X) || X <-XS];
pmap(Mapper,XS,Timeout)->
Myself = self(),
[spawn(fun()-> Myself ! Mapper(X) end) || X <- XS],
map_receive(length(XS),[],Timeout).
map_receive(0,Acc,_) -> Acc;
map_receive(N,Acc,Timeout)->
receive
Res -> map_receive(N-1,[Res|Acc],Timeout)
after
Timeout -> Acc
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment