--- AnyEvent-MP/MP.pm 2009/08/15 04:34:34 1.57 +++ AnyEvent-MP/MP.pm 2009/08/24 08:04:52 1.60 @@ -128,9 +128,9 @@ our $VERSION = $AnyEvent::MP::Kernel::VERSION; our @EXPORT = qw( - NODE $NODE *SELF node_of _any_ + NODE $NODE *SELF node_of after resolve_node initialise_node - snd rcv mon kil reg psub spawn + snd rcv mon mob_guard kil reg psub spawn port ); @@ -398,7 +398,7 @@ my $port = shift; my ($noderef, $portid) = split /#/, $port, 2; - ($NODE{$noderef} || add_node $noderef) == $NODE{""} + $NODE{$noderef} == $NODE{""} or Carp::croak "$port: rcv can only be called on local ports, caught"; while (@_) { @@ -507,6 +507,9 @@ port). After the monitoring action was invoked, further messages might get delivered again. +Note that monitoring-actions are one-shot: once released, they are removed +and will not trigger again. + In the first form (callback), the callback is simply called with any number of C<@reason> elements (no @reason means that the port was deleted "normally"). Note also that I<< the callback B never die >>, so use @@ -681,6 +684,28 @@ "$noderef#$id" } +=item after $timeout, @msg + +=item after $timeout, $callback + +Either sends the given message, or call the given callback, after the +specified number of seconds. + +This is simply a utility function that come sin handy at times. + +=cut + +sub after($@) { + my ($timeout, @action) = @_; + + my $t; $t = AE::timer $timeout, 0, sub { + undef $t; + ref $action[0] + ? $action[0]() + : snd @action; + }; +} + =back =head1 AnyEvent::MP vs. Distributed Erlang