Skip to content

Instantly share code, notes, and snippets.

@fabjan
Forked from Gustav-Simonsson/gist:2597846
Created May 4, 2012 21:38
Show Gist options
  • Save fabjan/2597916 to your computer and use it in GitHub Desktop.
Save fabjan/2597916 to your computer and use it in GitHub Desktop.
-module(foo).
-compile(export_all).
%%% Prints the given string `Num_times` times, with `Time_between` milliseconds
%%% between each print.
printer(Text, Num_times, Time_between) ->
[begin
io:format(Text),
% Wait a moment before next print
timer:sleep(Time_between)
end
|| _ <- lists:seq(1, Num_times)].
main() ->
Printers =
[spawn_link(?MODULE, printer, ["Hello~n", 30, 10]),
spawn_link(?MODULE, printer, ["World~n", 40, 15]),
spawn_link(?MODULE, printer, ["Parallel World~n", 40, 20])],
process_flag(trap_exit, true),
lists:foreach(Printers, fun (Printer) ->
receive
{'EXIT', Printer, normal} -> ok
end
end).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment