S. Carton":32qblljp said:In erlang:
Code:-module(sleep_sort). -compile(export_all). sorter(Num) -> timer:sleep(Num * 1000), io:format("~p~n", [Num]). sort(Num_list) -> lists:foreach(fun (N) -> spawn_link(?MODULE, sorter, [N]) end, Num_list).
Usage is:
Code:Erlang R14B01 (erts-5.8.2) [source] [rq] [async-threads:0] [hipe] [kernel-poll:false] Eshell V5.8.2 (abort with ^G) 1> c(sleep_sort). {ok,sleep_sort} 2> sleep_sort:sort([1,4,3,5,2]). ok 1 2 3 4 5 3>
Cool. But you could make it more useful by collecting the results back into a list.