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.53 by root, Fri Aug 14 15:31:21 2009 UTC vs.
Revision 1.54 by root, Fri Aug 14 16:15:37 2009 UTC

348The default callback received all messages not matched by a more specific 348The default callback received all messages not matched by a more specific
349C<tag> match. 349C<tag> match.
350 350
351=item rcv $local_port, tag => $callback->(@msg_without_tag), ... 351=item rcv $local_port, tag => $callback->(@msg_without_tag), ...
352 352
353Register callbacks to be called on messages starting with the given tag on 353Register (or replace) callbacks to be called on messages starting with the
354the given port (and return the port), or unregister it (when C<$callback> 354given tag on the given port (and return the port), or unregister it (when
355is C<$undef>). 355C<$callback> is C<$undef> or missing). There can only be one callback
356registered for each tag.
356 357
357The original message will be passed to the callback, after the first 358The original message will be passed to the callback, after the first
358element (the tag) has been removed. The callback will use the same 359element (the tag) has been removed. The callback will use the same
359environment as the default callback (see above). 360environment as the default callback (see above).
360 361
371 snd $otherport, reply => 372 snd $otherport, reply =>
372 rcv port, 373 rcv port,
373 msg1 => sub { ... }, 374 msg1 => sub { ... },
374 ... 375 ...
375 ; 376 ;
377
378Example: temporarily register a rcv callback for a tag matching some port
379(e.g. for a rpc reply) and unregister it after a message was received.
380
381 rcv $port, $otherport => sub {
382 my @reply = @_;
383
384 rcv $SELF, $otherport;
385 };
376 386
377=cut 387=cut
378 388
379sub rcv($@) { 389sub rcv($@) {
380 my $port = shift; 390 my $port = shift;
735convenience functionality. 745convenience functionality.
736 746
737This means that AEMP requires a less tightly controlled environment at the 747This means that AEMP requires a less tightly controlled environment at the
738cost of longer node references and a slightly higher management overhead. 748cost of longer node references and a slightly higher management overhead.
739 749
740=item Erlang has a "remote ports are like local ports" philosophy, AEMP 750=item * Erlang has a "remote ports are like local ports" philosophy, AEMP
741uses "local ports are like remote ports". 751uses "local ports are like remote ports".
742 752
743The failure modes for local ports are quite different (runtime errors 753The failure modes for local ports are quite different (runtime errors
744only) then for remote ports - when a local port dies, you I<know> it dies, 754only) then for remote ports - when a local port dies, you I<know> it dies,
745when a connection to another node dies, you know nothing about the other 755when a connection to another node dies, you know nothing about the other

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines