… | |
… | |
126 | use base "Exporter"; |
126 | use base "Exporter"; |
127 | |
127 | |
128 | our $VERSION = $AnyEvent::MP::Kernel::VERSION; |
128 | our $VERSION = $AnyEvent::MP::Kernel::VERSION; |
129 | |
129 | |
130 | our @EXPORT = qw( |
130 | our @EXPORT = qw( |
131 | NODE $NODE *SELF node_of _any_ |
131 | NODE $NODE *SELF node_of after |
132 | resolve_node initialise_node |
132 | resolve_node initialise_node |
133 | snd rcv mon kil reg psub spawn |
133 | snd rcv mon mob_guard kil reg psub spawn |
134 | port |
134 | port |
135 | ); |
135 | ); |
136 | |
136 | |
137 | our $SELF; |
137 | our $SELF; |
138 | |
138 | |
… | |
… | |
396 | |
396 | |
397 | sub rcv($@) { |
397 | sub rcv($@) { |
398 | my $port = shift; |
398 | my $port = shift; |
399 | my ($noderef, $portid) = split /#/, $port, 2; |
399 | my ($noderef, $portid) = split /#/, $port, 2; |
400 | |
400 | |
401 | ($NODE{$noderef} || add_node $noderef) == $NODE{""} |
401 | $NODE{$noderef} == $NODE{""} |
402 | or Carp::croak "$port: rcv can only be called on local ports, caught"; |
402 | or Carp::croak "$port: rcv can only be called on local ports, caught"; |
403 | |
403 | |
404 | while (@_) { |
404 | while (@_) { |
405 | if (ref $_[0]) { |
405 | if (ref $_[0]) { |
406 | if (my $self = $PORT_DATA{$portid}) { |
406 | if (my $self = $PORT_DATA{$portid}) { |
… | |
… | |
505 | message loss has been detected. No messages will be lost "in between" |
505 | message loss has been detected. No messages will be lost "in between" |
506 | (after the first lost message no further messages will be received by the |
506 | (after the first lost message no further messages will be received by the |
507 | port). After the monitoring action was invoked, further messages might get |
507 | port). After the monitoring action was invoked, further messages might get |
508 | delivered again. |
508 | delivered again. |
509 | |
509 | |
|
|
510 | Note that monitoring-actions are one-shot: once released, they are removed |
|
|
511 | and will not trigger again. |
|
|
512 | |
510 | In the first form (callback), the callback is simply called with any |
513 | In the first form (callback), the callback is simply called with any |
511 | number of C<@reason> elements (no @reason means that the port was deleted |
514 | number of C<@reason> elements (no @reason means that the port was deleted |
512 | "normally"). Note also that I<< the callback B<must> never die >>, so use |
515 | "normally"). Note also that I<< the callback B<must> never die >>, so use |
513 | C<eval> if unsure. |
516 | C<eval> if unsure. |
514 | |
517 | |
… | |
… | |
679 | snd_to_func $noderef, "AnyEvent::MP::_spawn" => $id, @_; |
682 | snd_to_func $noderef, "AnyEvent::MP::_spawn" => $id, @_; |
680 | |
683 | |
681 | "$noderef#$id" |
684 | "$noderef#$id" |
682 | } |
685 | } |
683 | |
686 | |
|
|
687 | =item after $timeout, @msg |
|
|
688 | |
|
|
689 | =item after $timeout, $callback |
|
|
690 | |
|
|
691 | Either sends the given message, or call the given callback, after the |
|
|
692 | specified number of seconds. |
|
|
693 | |
|
|
694 | This is simply a utility function that come sin handy at times. |
|
|
695 | |
|
|
696 | =cut |
|
|
697 | |
|
|
698 | sub after($@) { |
|
|
699 | my ($timeout, @action) = @_; |
|
|
700 | |
|
|
701 | my $t; $t = AE::timer $timeout, 0, sub { |
|
|
702 | undef $t; |
|
|
703 | ref $action[0] |
|
|
704 | ? $action[0]() |
|
|
705 | : snd @action; |
|
|
706 | }; |
|
|
707 | } |
|
|
708 | |
684 | =back |
709 | =back |
685 | |
710 | |
686 | =head1 AnyEvent::MP vs. Distributed Erlang |
711 | =head1 AnyEvent::MP vs. Distributed Erlang |
687 | |
712 | |
688 | AnyEvent::MP got lots of its ideas from distributed Erlang (Erlang node |
713 | AnyEvent::MP got lots of its ideas from distributed Erlang (Erlang node |