Created
May 16, 2013 08:42
-
-
Save abolibibelot/5590316 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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