How to use mnesia:subscribe

Hakan Mattsson hakan@REDACTED
Thu Mar 10 15:54:55 CET 2005


On Thu, 10 Mar 2005, Dietmar Schaefer wrote:

DS> Actually  - I need to know how (and where) to receive the event.
DS> 
DS> Any sample code ??

The events are sent as messages to the process that invokes
mnesia:subscribe/1. 

See the Mnesia User's Guide about the event handling details:

  http://www.erlang.se/doc/doc-5.4.3/lib/mnesia-4.2/doc/html/Mnesia_chap5.html#5.7

/Håkan

% erl
Erlang (BEAM) emulator version 5.4.3 [source] [hipe] [threads:0]

Eshell V5.4.3  (abort with ^G)
1> mnesia:start().
ok
2> mnesia:create_table(t, []).
{atomic,ok}
3> mnesia:subscribe({table, t, simple}).
{ok,nonode@REDACTED}
4> [mnesia:dirty_write({t, K, K * K}) || K <- lists:seq(1, 3)].
[ok,ok,ok]
5> mnesia:dirty_delete(t, 2).
ok
6> flush().
Shell got {mnesia_table_event,{write,{t,1,1},{dirty,<0.30.0>}}}
Shell got {mnesia_table_event,{write,{t,2,4},{dirty,<0.30.0>}}}
Shell got {mnesia_table_event,{write,{t,3,9},{dirty,<0.30.0>}}}
Shell got {mnesia_table_event,{delete,{t,2},{dirty,<0.30.0>}}}
ok
7>


More information about the erlang-questions mailing list