Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -module(sleepsort).
- -export([sort/1]).
- % hacky short (still readable) sleepsort, now actually using sleep() call!
- % see http://news.ycombinator.com/item?id=2657738
- sort(Ns) ->
- Src = self(),
- [ spawn(fun() -> timer:sleep(N), Src ! {sorted, N} end) || N <- Ns ],
- [ fun() -> receive {sorted, N} -> N end end() || _ <- Ns ].
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement