--- AnyEvent-MP/MP.pm 2009/08/14 15:13:20 1.52 +++ AnyEvent-MP/MP.pm 2009/08/14 23:17:17 1.55 @@ -25,7 +25,7 @@ snd @msg_with_first_element_being_a_port; # creating/using ports, the simple way - my $somple_port = port { my @msg = @_; 0 }; + my $simple_port = port { my @msg = @_; 0 }; # creating/using ports, tagged message matching my $port = port; @@ -71,22 +71,21 @@ A port is something you can send messages to (with the C function). -Some ports allow you to register C handlers that can match specific -messages. All C handlers will receive messages they match, messages -will not be queued. +Ports allow you to register C handlers that can match all or just +some messages. Messages will not be queued. =item port id - C -A port id is normaly the concatenation of a noderef, a hash-mark (C<#>) as +A port ID is the concatenation of a noderef, a hash-mark (C<#>) as separator, and a port name (a printable string of unspecified format). An exception is the the node port, whose ID is identical to its node reference. =item node -A node is a single process containing at least one port - the node -port. You can send messages to node ports to find existing ports or to -create new ports, among other things. +A node is a single process containing at least one port - the node port, +which provides nodes to manage each other remotely, and to create new +ports. Nodes are either private (single-process only), slaves (connected to a master node only) or public nodes (connectable from unrelated nodes). @@ -351,9 +350,10 @@ =item rcv $local_port, tag => $callback->(@msg_without_tag), ... -Register callbacks to be called on messages starting with the given tag on -the given port (and return the port), or unregister it (when C<$callback> -is C<$undef>). +Register (or replace) callbacks to be called on messages starting with the +given tag on the given port (and return the port), or unregister it (when +C<$callback> is C<$undef> or missing). There can only be one callback +registered for each tag. The original message will be passed to the callback, after the first element (the tag) has been removed. The callback will use the same @@ -375,6 +375,15 @@ ... ; +Example: temporarily register a rcv callback for a tag matching some port +(e.g. for a rpc reply) and unregister it after a message was received. + + rcv $port, $otherport => sub { + my @reply = @_; + + rcv $SELF, $otherport; + }; + =cut sub rcv($@) { @@ -659,8 +668,7 @@ $_[0] =~ /::/ or Carp::croak "spawn init function must be a fully-qualified name, caught"; - ($NODE{$noderef} || add_node $noderef) - ->send (["", "AnyEvent::MP::_spawn" => $id, @_]); + snd_to_func $noderef, "AnyEvent::MP::_spawn" => $id, @_; "$noderef#$id" } @@ -738,7 +746,7 @@ This means that AEMP requires a less tightly controlled environment at the cost of longer node references and a slightly higher management overhead. -=item Erlang has a "remote ports are like local ports" philosophy, AEMP +=item * Erlang has a "remote ports are like local ports" philosophy, AEMP uses "local ports are like remote ports". The failure modes for local ports are quite different (runtime errors