Created
October 10, 2014 13:24
-
-
Save dergraf/b3aa9d495110ff30a010 to your computer and use it in GitHub Desktop.
set up a function call in its own process
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
make_request(Fun, Args) when is_function(Fun), is_list(Args) -> | |
Ref = make_ref(), | |
Caller = {self(), Ref}, | |
ReqF = fun() -> | |
exit({Ref, apply(Fun, [Caller|Args])}) | |
end, | |
try spawn_monitor(ReqF) of | |
{_, MRef} -> | |
receive | |
Ref -> | |
erlang:demonitor(MRef, [flush]), | |
ok; | |
{'DOWN', MRef, process, Reason} -> | |
{error, Reason} | |
end | |
catch | |
error: system_limit = E -> | |
{error, E} | |
end. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment