Skip to content

Instantly share code, notes, and snippets.

@shino
Created September 12, 2010 12:05
Show Gist options
  • Save shino/576026 to your computer and use it in GitHub Desktop.
Save shino/576026 to your computer and use it in GitHub Desktop.
-module(overload_handler_sample).
-auther(shino.shun@gmail.com).
-compile(export_all).
%% -record(rec, {k, v1, v2, v3}).
main() ->
%% Mnesia 開始前には subscribe してもアラートは受け取れない
subscribe_to_mnesia(before_mnesia_start),
mnesia:start(),
%% Mnesia 停止すると、以前のサブスクライバは、アラートを受け取れない
subscribe_to_mnesia(after_mnesia_start),
mnesia:stop(),
timer:sleep(500),
mnesia:start(),
subscribe_to_mnesia(after_mnesia_restart),
%% 複数のサブスクライバも可能
subscribe_to_mnesia(after_mnesia_restart2),
mnesia:stop().
subscribe_to_mnesia(Tag) ->
spawn_link(fun() -> consume_messages(Tag) end).
consume_messages(Tag) ->
mnesia:subscribe(system),
receive
Alert ->
io:format("[‾p] ‾p‾n", [Tag, Alert])
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment