Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -module(pmap_any_tmt).
- -compile(export_all).
- fib(1) -> 1;
- fib(2) -> 1;
- fib(N) -> fib(N-1) + fib(N-2).
- pmap_any_tagged_max_time(F, L, MaxTime) ->
- S = self(),
- smap(fun(I) ->
- spawn(fun() -> do_f(S, F, I) end)
- end, L),
- timer:send_after(MaxTime, self(), finish),
- gather(length(L), []).
- smap(_, []) ->
- [];
- smap(F, [H|T]) ->
- [F(H) | smap(F, T)].
- do_f(Parent, F, I) ->
- Parent ! {I, F(I)}.
- gather(0, L) ->
- lists:reverse(L);
- gather(Left, L) ->
- receive
- {Tag, Ret} ->
- gather(Left-1, [{Tag, Ret}|L]);
- finish ->
- gather(0, L)
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement