… | |
… | |
156 | }; |
156 | }; |
157 | |
157 | |
158 | $self |
158 | $self |
159 | } |
159 | } |
160 | |
160 | |
161 | =item $portid = create_miniport { } |
161 | =item $portid = miniport { my @msg = @_; $finished } |
162 | |
162 | |
163 | Creates a "mini port", that is, a port without much #TODO |
163 | Creates a "mini port", that is, a very lightweight port without any |
|
|
164 | pattern matching behind it, and returns its ID. |
164 | |
165 | |
165 | =cut |
166 | The block will be called for every message received on the port. When the |
|
|
167 | callback returns a true value its job is considered "done" and the port |
|
|
168 | will be destroyed. Otherwise it will stay alive. |
166 | |
169 | |
|
|
170 | The message will be passed as-is, no extra argument (ie.. no port id) will |
|
|
171 | be passed to the callback. |
|
|
172 | |
|
|
173 | If you need the local port id in the callback, this works nicely: |
|
|
174 | |
|
|
175 | my $port; $port = miniport { |
|
|
176 | snd $otherport, reply => $port; |
|
|
177 | }; |
|
|
178 | |
|
|
179 | =cut |
|
|
180 | |
167 | sub create_miniport(&) { |
181 | sub miniport(&) { |
168 | my $cb = shift; |
182 | my $cb = shift; |
169 | my $id = "$AnyEvent::MP::Base::UNIQ." . ++$AnyEvent::MP::Base::ID; |
183 | my $id = "$AnyEvent::MP::Base::UNIQ." . ++$AnyEvent::MP::Base::ID; |
170 | |
184 | |
171 | $AnyEvent::MP::Base::PORT{$id} = sub { |
185 | $AnyEvent::MP::Base::PORT{$id} = sub { |
172 | $_[0] = "$NODE#$id"; |
|
|
173 | &$cb |
186 | &$cb |
174 | and delete $AnyEvent::MP::Base::PORT{$id}; |
187 | and delete $AnyEvent::MP::Base::PORT{$id}; |
175 | }; |
188 | }; |
176 | |
189 | |
177 | "$NODE#$id" |
190 | "$NODE#$id" |