Created
May 13, 2015 14:37
-
-
Save Rembane/1a95c957031e1a7935d1 to your computer and use it in GitHub Desktop.
How to get messages in correct order, with interference.
This file contains hidden or 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
-module(msgorder). | |
-compile(export_all). | |
% How to get messages in correct order, even though things outside of our | |
% control try to put them in a semi-random order. | |
f(T, X) -> | |
Parent = self(), | |
Ref = make_ref(), | |
spawn_link(fun() -> timer:send_after(T, Parent, {Ref, {T, X}}) end), | |
receive {Ref, Y} -> Y end. | |
test() -> | |
lists:map(fun (X) -> f(random:uniform(10)*100, X) end, lists:seq(1,10)). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
why
spawn_link
andtimer:send_after
? You could've just done: