@@ -150,7 +150,7 @@ come in a variety of forms, each one appropriate for a different use case. In
150
150
what follows, we cover the most commonly used varieties.
151
151
152
152
The simplest way to create a pipe is to use the ` pipes::stream `
153
- function to create a ` (Chan, Port ) ` pair. In Rust parlance, a * channel*
153
+ function to create a ` (Port, Chan ) ` pair. In Rust parlance, a * channel*
154
154
is a sending endpoint of a pipe, and a * port* is the receiving
155
155
endpoint. Consider the following example of calculating two results
156
156
concurrently:
@@ -159,7 +159,7 @@ concurrently:
159
159
use task::spawn;
160
160
use pipes::{stream, Port, Chan};
161
161
162
- let (chan, port ): (Chan <int>, Port <int>) = stream();
162
+ let (port, chan ): (Port <int>, Chan <int>) = stream();
163
163
164
164
do spawn |move chan| {
165
165
let result = some_expensive_computation();
@@ -179,7 +179,7 @@ a tuple into its component parts).
179
179
180
180
~~~~
181
181
# use pipes::{stream, Chan, Port};
182
- let (chan, port ): (Chan <int>, Port <int>) = stream();
182
+ let (port, chan ): (Port <int>, Chan <int>) = stream();
183
183
~~~~
184
184
185
185
The child task will use the channel to send data to the parent task,
@@ -191,7 +191,7 @@ spawns the child task.
191
191
# use task::spawn;
192
192
# use pipes::{stream, Port, Chan};
193
193
# fn some_expensive_computation() -> int { 42 }
194
- # let (chan, port ) = stream();
194
+ # let (port, chan ) = stream();
195
195
do spawn |move chan| {
196
196
let result = some_expensive_computation();
197
197
chan.send(result);
@@ -211,7 +211,7 @@ port:
211
211
~~~~
212
212
# use pipes::{stream, Port, Chan};
213
213
# fn some_other_expensive_computation() {}
214
- # let (chan, port ) = stream::<int>();
214
+ # let (port, chan ) = stream::<int>();
215
215
# chan.send(0);
216
216
some_other_expensive_computation();
217
217
let result = port.recv();
@@ -227,7 +227,7 @@ following program is ill-typed:
227
227
# use task::{spawn};
228
228
# use pipes::{stream, Port, Chan};
229
229
# fn some_expensive_computation() -> int { 42 }
230
- let (chan, port ) = stream();
230
+ let (port, chan ) = stream();
231
231
232
232
do spawn |move chan| {
233
233
chan.send(some_expensive_computation());
@@ -247,7 +247,7 @@ Instead we can use a `SharedChan`, a type that allows a single
247
247
# use task::spawn;
248
248
use pipes::{stream, SharedChan};
249
249
250
- let (chan, port ) = stream();
250
+ let (port, chan ) = stream();
251
251
let chan = SharedChan(move chan);
252
252
253
253
for uint::range(0, 3) |init_val| {
@@ -282,7 +282,7 @@ might look like the example below.
282
282
283
283
// Create a vector of ports, one for each child task
284
284
let ports = do vec::from_fn(3) |init_val| {
285
- let (chan, port ) = stream();
285
+ let (port, chan ) = stream();
286
286
do spawn |move chan| {
287
287
chan.send(some_expensive_computation(init_val));
288
288
}
@@ -397,7 +397,7 @@ before returning. Hence:
397
397
# use task::{spawn, try};
398
398
# fn sleep_forever() { loop { task::yield() } }
399
399
# do task::try {
400
- let (sender, receiver ): (Chan <int>, Port <int>) = stream();
400
+ let (receiver, sender ): (Port <int>, Chan <int>) = stream();
401
401
do spawn |move receiver| { // Bidirectionally linked
402
402
// Wait for the supervised child task to exist.
403
403
let message = receiver.recv();
0 commit comments