… | |
… | |
348 | The default callback received all messages not matched by a more specific |
348 | The default callback received all messages not matched by a more specific |
349 | C<tag> match. |
349 | C<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 | |
353 | Register callbacks to be called on messages starting with the given tag on |
353 | Register (or replace) callbacks to be called on messages starting with the |
354 | the given port (and return the port), or unregister it (when C<$callback> |
354 | given tag on the given port (and return the port), or unregister it (when |
355 | is C<$undef>). |
355 | C<$callback> is C<$undef> or missing). There can only be one callback |
|
|
356 | registered for each tag. |
356 | |
357 | |
357 | The original message will be passed to the callback, after the first |
358 | The original message will be passed to the callback, after the first |
358 | element (the tag) has been removed. The callback will use the same |
359 | element (the tag) has been removed. The callback will use the same |
359 | environment as the default callback (see above). |
360 | environment 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 | |
|
|
378 | Example: 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 | |
379 | sub rcv($@) { |
389 | sub rcv($@) { |
380 | my $port = shift; |
390 | my $port = shift; |
… | |
… | |
735 | convenience functionality. |
745 | convenience functionality. |
736 | |
746 | |
737 | This means that AEMP requires a less tightly controlled environment at the |
747 | This means that AEMP requires a less tightly controlled environment at the |
738 | cost of longer node references and a slightly higher management overhead. |
748 | cost 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 |
741 | uses "local ports are like remote ports". |
751 | uses "local ports are like remote ports". |
742 | |
752 | |
743 | The failure modes for local ports are quite different (runtime errors |
753 | The failure modes for local ports are quite different (runtime errors |
744 | only) then for remote ports - when a local port dies, you I<know> it dies, |
754 | only) then for remote ports - when a local port dies, you I<know> it dies, |
745 | when a connection to another node dies, you know nothing about the other |
755 | when a connection to another node dies, you know nothing about the other |