… | |
… | |
25 | snd @msg_with_first_element_being_a_port; |
25 | snd @msg_with_first_element_being_a_port; |
26 | |
26 | |
27 | # creating/using ports, the simple way |
27 | # creating/using ports, the simple way |
28 | my $somple_port = port { my @msg = @_; 0 }; |
28 | my $somple_port = port { my @msg = @_; 0 }; |
29 | |
29 | |
30 | # creating/using ports, type matching |
30 | # creating/using ports, tagged message matching |
31 | my $port = port; |
31 | my $port = port; |
32 | rcv $port, ping => sub { snd $_[0], "pong"; 0 }; |
32 | rcv $port, ping => sub { snd $_[0], "pong"; 0 }; |
33 | rcv $port, pong => sub { warn "pong received\n"; 0 }; |
33 | rcv $port, pong => sub { warn "pong received\n"; 0 }; |
34 | |
34 | |
35 | # create a port on another node |
35 | # create a port on another node |
… | |
… | |
143 | kil $SELF, die => $msg; |
143 | kil $SELF, die => $msg; |
144 | } |
144 | } |
145 | |
145 | |
146 | =item $thisnode = NODE / $NODE |
146 | =item $thisnode = NODE / $NODE |
147 | |
147 | |
148 | The C<NODE> function returns, and the C<$NODE> variable contains |
148 | The C<NODE> function returns, and the C<$NODE> variable contains the |
149 | the noderef of the local node. The value is initialised by a call |
149 | noderef of the local node. The value is initialised by a call to |
150 | to C<become_public> or C<become_slave>, after which all local port |
150 | C<initialise_node>. |
151 | identifiers become invalid. |
|
|
152 | |
151 | |
153 | =item $noderef = node_of $port |
152 | =item $noderef = node_of $port |
154 | |
153 | |
155 | Extracts and returns the noderef from a portid or a noderef. |
154 | Extracts and returns the noderef from a port ID or a noderef. |
156 | |
155 | |
157 | =item initialise_node $noderef, $seednode, $seednode... |
156 | =item initialise_node $noderef, $seednode, $seednode... |
158 | |
157 | |
159 | =item initialise_node "slave/", $master, $master... |
158 | =item initialise_node "slave/", $master, $master... |
160 | |
159 | |
… | |
… | |
279 | =item snd $port, type => @data |
278 | =item snd $port, type => @data |
280 | |
279 | |
281 | =item snd $port, @msg |
280 | =item snd $port, @msg |
282 | |
281 | |
283 | Send the given message to the given port ID, which can identify either |
282 | Send the given message to the given port ID, which can identify either |
284 | a local or a remote port, and can be either a string or soemthignt hat |
283 | a local or a remote port, and must be a port ID. |
285 | stringifies a sa port ID (such as a port object :). |
|
|
286 | |
284 | |
287 | While the message can be about anything, it is highly recommended to use a |
285 | While the message can be about anything, it is highly recommended to use a |
288 | string as first element (a portid, or some word that indicates a request |
286 | string as first element (a port ID, or some word that indicates a request |
289 | type etc.). |
287 | type etc.). |
290 | |
288 | |
291 | The message data effectively becomes read-only after a call to this |
289 | The message data effectively becomes read-only after a call to this |
292 | function: modifying any argument is not allowed and can cause many |
290 | function: modifying any argument is not allowed and can cause many |
293 | problems. |
291 | problems. |