Skip to content

Instantly share code, notes, and snippets.

@MichaelDrogalis
Last active December 12, 2015 03:58
Show Gist options
  • Save MichaelDrogalis/4710815 to your computer and use it in GitHub Desktop.
Save MichaelDrogalis/4710815 to your computer and use it in GitHub Desktop.
-module(core).
-export([future/1, f/0]).
f() ->
timer:sleep(20000),
"My result.".
future(F) ->
Res = F(), % Evaluate ASAP.
receive % Wait until it's dereferenced to divulge the result.
dereference ->
io:format("~s~n", [Res]);
_ ->
io:format("Invalid command.~n")
end.
% 1> c(core).
% {ok,core}
% 2> P = spawn(core, future, [fun core:f/0]).
% <0.39.0>
% 3> P ! dereference.
% dereference
% 4> % Waiting...
% My result.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment