Skip to content

Commit 5f57588

Browse files
committed
Update the rock-paper-scissors example in the tutorial, and rename some types in core::pipes
1 parent b592d57 commit 5f57588

12 files changed

+36
-37
lines changed

doc/tutorial.md

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Here's a parallel game of rock, paper, scissors to whet your appetite.
7474
~~~~
7575
use std;
7676
77-
import comm::listen;
77+
import pipes::PortSet;
7878
import task::spawn;
7979
import iter::repeat;
8080
import rand::{seeded_rng, seed};
@@ -83,25 +83,24 @@ import io::println;
8383
8484
fn main() {
8585
// Open a channel to receive game results
86-
do listen |result_from_game| {
87-
88-
let times = 10;
89-
let player1 = ~"graydon";
90-
let player2 = ~"patrick";
91-
92-
for repeat(times) {
93-
// Start another task to play the game
94-
do spawn |copy player1, copy player2| {
95-
let outcome = play_game(player1, player2);
96-
result_from_game.send(outcome);
97-
}
86+
let result_from_game = PortSet();
87+
let times = 10;
88+
let player1 = ~"graydon";
89+
let player2 = ~"patrick";
90+
91+
for repeat(times) {
92+
// Start another task to play the game
93+
let result = result_from_game.chan();
94+
do spawn |copy player1, copy player2| {
95+
let outcome = play_game(player1, player2);
96+
result.send(outcome);
9897
}
98+
}
9999
100-
// Report the results as the games complete
101-
for range(0, times) |round| {
102-
let winner = result_from_game.recv();
103-
println(#fmt("%s wins round #%u", winner, round));
104-
}
100+
// Report the results as the games complete
101+
for range(0, times) |round| {
102+
let winner = result_from_game.recv();
103+
println(#fmt("%s wins round #%u", winner, round));
105104
}
106105
107106
fn play_game(player1: ~str, player2: ~str) -> ~str {

src/compiletest/procsrv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn run(lib_path: ~str,
6060

6161

6262
writeclose(pipe_in.out, input);
63-
let p = pipes::port_set();
63+
let p = pipes::PortSet();
6464
let ch = p.chan();
6565
do task::spawn_sched(task::SingleThreaded) {
6666
let errput = readclose(pipe_err.in);

src/libcore/pipes.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export atomic_add_acq, atomic_sub_rel;
9393
export send_packet, recv_packet, send, recv, try_recv, peek;
9494
export select, select2, selecti, select2i, selectable;
9595
export spawn_service, spawn_service_recv;
96-
export stream, port, chan, shared_chan, port_set, channel;
96+
export stream, port, chan, SharedChan, PortSet, channel;
9797
export oneshot, chan_one, port_one;
9898
export recv_one, try_recv_one, send_one, try_send_one;
9999

@@ -1020,8 +1020,8 @@ impl<T: send> port<T>: recv<T> {
10201020
}
10211021
}
10221022

1023-
// Treat a whole bunch of ports as one.
1024-
struct port_set<T: send> : recv<T> {
1023+
/// Treat many ports as one.
1024+
struct PortSet<T: send> : recv<T> {
10251025
let mut ports: ~[pipes::port<T>];
10261026

10271027
new() { self.ports = ~[]; }
@@ -1096,9 +1096,9 @@ impl<T: send> port<T>: selectable {
10961096
}
10971097

10981098
/// A channel that can be shared between many senders.
1099-
type shared_chan<T: send> = unsafe::Exclusive<chan<T>>;
1099+
type SharedChan<T: send> = unsafe::Exclusive<chan<T>>;
11001100

1101-
impl<T: send> shared_chan<T>: channel<T> {
1101+
impl<T: send> SharedChan<T>: channel<T> {
11021102
fn send(+x: T) {
11031103
let mut xx = some(x);
11041104
do self.with |chan| {
@@ -1119,7 +1119,7 @@ impl<T: send> shared_chan<T>: channel<T> {
11191119
}
11201120

11211121
/// Converts a `chan` into a `shared_chan`.
1122-
fn shared_chan<T:send>(+c: chan<T>) -> shared_chan<T> {
1122+
fn SharedChan<T:send>(+c: chan<T>) -> SharedChan<T> {
11231123
unsafe::exclusive(c)
11241124
}
11251125

src/libstd/arc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ mod tests {
423423
let (c, p) = pipes::stream();
424424

425425
do task::spawn() {
426-
let p = pipes::port_set();
426+
let p = pipes::PortSet();
427427
c.send(p.chan());
428428

429429
let arc_v = p.recv();

src/test/bench/msgsend-pipes-shared.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std;
1414
import io::Writer;
1515
import io::WriterUtil;
1616

17-
import pipes::{port, chan, shared_chan};
17+
import pipes::{port, chan, SharedChan};
1818

1919
macro_rules! move_out {
2020
{ $x:expr } => { unsafe { let y <- *ptr::addr_of($x); y } }
@@ -48,7 +48,7 @@ fn run(args: &[~str]) {
4848
let (to_parent, from_child) = pipes::stream();
4949
let (to_child, from_parent) = pipes::stream();
5050

51-
let to_child = shared_chan(to_child);
51+
let to_child = SharedChan(to_child);
5252

5353
let size = option::get(uint::from_str(args[1]));
5454
let workers = option::get(uint::from_str(args[2]));

src/test/bench/msgsend-pipes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std;
1010
import io::Writer;
1111
import io::WriterUtil;
1212

13-
import pipes::{port, port_set, chan};
13+
import pipes::{port, PortSet, chan};
1414

1515
macro_rules! move_out {
1616
{ $x:expr } => { unsafe { let y <- *ptr::addr_of($x); y } }
@@ -22,7 +22,7 @@ enum request {
2222
stop
2323
}
2424

25-
fn server(requests: port_set<request>, responses: pipes::chan<uint>) {
25+
fn server(requests: PortSet<request>, responses: pipes::chan<uint>) {
2626
let mut count = 0u;
2727
let mut done = false;
2828
while !done {
@@ -43,7 +43,7 @@ fn server(requests: port_set<request>, responses: pipes::chan<uint>) {
4343
fn run(args: &[~str]) {
4444
let (to_parent, from_child) = pipes::stream();
4545
let (to_child, from_parent_) = pipes::stream();
46-
let from_parent = port_set();
46+
let from_parent = PortSet();
4747
from_parent.add(from_parent_);
4848

4949
let size = option::get(uint::from_str(args[1]));

src/test/bench/shootout-pfib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn fib(n: int) -> int {
3030
} else if n <= 2 {
3131
c.send(1);
3232
} else {
33-
let p = pipes::port_set();
33+
let p = pipes::PortSet();
3434
let ch = p.chan();
3535
task::spawn(|| pfib(ch, n - 1) );
3636
let ch = p.chan();

src/test/run-pass/task-comm-14.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import task;
22

33
fn main() {
4-
let po = pipes::port_set();
4+
let po = pipes::PortSet();
55

66
// Spawn 10 tasks each sending us back one int.
77
let mut i = 10;

src/test/run-pass/task-comm-3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn test00() {
2424

2525
debug!{"Creating tasks"};
2626

27-
let po = pipes::port_set();
27+
let po = pipes::PortSet();
2828

2929
let mut i: int = 0;
3030

src/test/run-pass/task-comm-6.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn main() { test00(); }
99
fn test00() {
1010
let mut r: int = 0;
1111
let mut sum: int = 0;
12-
let p = pipes::port_set();
12+
let p = pipes::PortSet();
1313
let c0 = p.chan();
1414
let c1 = p.chan();
1515
let c2 = p.chan();

src/test/run-pass/task-comm-7.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn test00_start(c: pipes::chan<int>, start: int, number_of_messages: int) {
1111
fn test00() {
1212
let mut r: int = 0;
1313
let mut sum: int = 0;
14-
let p = pipes::port_set();
14+
let p = pipes::PortSet();
1515
let number_of_messages: int = 10;
1616

1717
let c = p.chan();

src/test/run-pass/task-comm-9.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn test00_start(c: pipes::chan<int>, number_of_messages: int) {
1111
fn test00() {
1212
let r: int = 0;
1313
let mut sum: int = 0;
14-
let p = pipes::port_set();
14+
let p = pipes::PortSet();
1515
let number_of_messages: int = 10;
1616
let ch = p.chan();
1717

0 commit comments

Comments
 (0)