--- AnyEvent-MP/MP.pm 2009/08/02 18:26:00 1.14 +++ AnyEvent-MP/MP.pm 2009/08/02 19:25:27 1.15 @@ -158,18 +158,31 @@ $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; $AnyEvent::MP::Base::PORT{$id} = sub { -# unshift @_, "$NODE#$id"; &$cb and delete $AnyEvent::MP::Base::PORT{$id}; };