--- AnyEvent-MP/MP.pm 2009/08/02 18:08:38 1.11 +++ AnyEvent-MP/MP.pm 2009/08/02 19:29:41 1.16 @@ -127,7 +127,7 @@ =cut sub create_port { - my $id = "$AnyEvent::MP::Base::UNIQ." . ++$AnyEvent::MP::Base::ID; + my $id = "$AnyEvent::MP::Base::UNIQ." . $AnyEvent::MP::Base::ID++; my $self = bless { id => "$NODE#$id", @@ -158,15 +158,29 @@ $self } -=item $portid = create_miniport { } +=item $portid = miniport { my @msg = @_; $finished } -Creates a "mini port", that is, a port without much #TODO +Creates a "mini port", that is, a very lightweight port without any +pattern matching behind it, and returns its ID. + +The block will be called for every message received on the port. When the +callback returns a true value its job is considered "done" and the port +will be destroyed. Otherwise it will stay alive. + +The message will be passed as-is, no extra argument (ie.. no port id) will +be passed to the callback. + +If you need the local port id in the callback, this works nicely: + + my $port; $port = miniport { + snd $otherport, reply => $port; + }; =cut -sub create_miniport(&) { +sub miniport(&) { my $cb = shift; - my $id = "$AnyEvent::MP::Base::UNIQ." . ++$AnyEvent::MP::Base::ID; + my $id = "$AnyEvent::MP::Base::UNIQ." . $AnyEvent::MP::Base::ID++; $AnyEvent::MP::Base::PORT{$id} = sub { &$cb