ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-MP/MP.pm
(Generate patch)

Comparing AnyEvent-MP/MP.pm (file contents):
Revision 1.127 by root, Sat Mar 3 20:35:10 2012 UTC vs.
Revision 1.128 by root, Sun Mar 4 14:28:44 2012 UTC

197 NODE $NODE *SELF node_of after 197 NODE $NODE *SELF node_of after
198 configure 198 configure
199 snd rcv mon mon_guard kil psub peval spawn cal 199 snd rcv mon mon_guard kil psub peval spawn cal
200 port 200 port
201 db_set db_del db_reg 201 db_set db_del db_reg
202 db_mon db_family db_keys db_values
202); 203);
203 204
204our $SELF; 205our $SELF;
205 206
206sub _self_die() { 207sub _self_die() {
946 947
947Sets the key on the database and returns a guard. When the guard is 948Sets the key on the database and returns a guard. When the guard is
948destroyed, the key is deleted from the database. If C<$value> is missing, 949destroyed, the key is deleted from the database. If C<$value> is missing,
949then C<undef> is used. 950then C<undef> is used.
950 951
952=item $guard = db_mon $family => $cb->($familyhash, \@subkeys...)
953
954Creates a monitor on the given database family. Each time a key is set or
955or is deleted the callback is called with a hash containing the database
956family and an arrayref with subkeys that have changed.
957
958Specifically, if one of the passed subkeys exists in the $familyhash, then
959it is currently set to the value in the $familyhash. Otherwise, it has
960been deleted.
961
962The first call will be with the current contents of the family and all
963keys, as if they were just added.
964
965It is possible that the callback is called with a change event even though
966the subkey is already present and the value has not changed.
967
968The monitoring stops when the guard object is destroyed.
969
970Example: on every change to the family "mygroup", print out all keys.
971
972 my $guard = db_mon mygroup => sub {
973 my ($family, $keys) = @_;
974 print "mygroup members: ", (join " ", keys %$family), "\n";
975 };
976
977Exmaple: wait until the family "My::Module::workers" is non-empty.
978
979 my $guard; $guard = db_mon My::Module::workers => sub {
980 my ($family, $keys) = @_;
981 return unless %$family;
982 undef $guard;
983 print "My::Module::workers now nonempty\n";
984 };
985
986Example: print all changes to the family "AnyRvent::Fantasy::Module".
987
988 my $guard = db_mon AnyRvent::Fantasy::Module => sub {
989 my ($family, $keys) = @_;
990
991 for (@$keys) {
992 print "$_: ",
993 (exists $family->{$_}
994 ? $family->{$_}
995 : "(deleted)"),
996 "\n";
997 }
998 };
999
951=cut 1000=cut
952 1001
953=back 1002=back
954 1003
955=head1 AnyEvent::MP vs. Distributed Erlang 1004=head1 AnyEvent::MP vs. Distributed Erlang

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines