Skip to content

Commit 80ef724

Browse files
committed
Remove spawn_listener, spawn_conversation
These are not needed in a pipe-based Rustiverse
1 parent dff2853 commit 80ef724

File tree

6 files changed

+40
-109
lines changed

6 files changed

+40
-109
lines changed

doc/tutorial-tasks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ and child both need to exchange messages with each other. The
461461
function `std::comm::DuplexStream()` supports this pattern. We'll
462462
look briefly at how to use it.
463463

464-
To see how `spawn_conversation()` works, we will create a child task
464+
To see how `DuplexStream()` works, we will create a child task
465465
that repeatedly receives a `uint` message, converts it to a string, and sends
466466
the string in response. The child terminates when it receives `0`.
467467
Here is the function that implements the child task:

src/libcore/task/mod.rs

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -433,43 +433,6 @@ impl TaskBuilder {
433433
}
434434
}
435435
436-
/**
437-
* Runs a new task while providing a channel from the parent to the child
438-
*
439-
* Sets up a communication channel from the current task to the new
440-
* child task, passes the port to child's body, and returns a channel
441-
* linked to the port to the parent.
442-
*
443-
* This encapsulates some boilerplate handshaking logic that would
444-
* otherwise be required to establish communication from the parent
445-
* to the child.
446-
*/
447-
fn spawn_listener<A: Owned>(f: fn~(comm::Port<A>)) -> comm::Chan<A> {
448-
let setup_po = comm::Port();
449-
let setup_ch = comm::Chan(&setup_po);
450-
do self.spawn |move f| {
451-
let po = comm::Port();
452-
let ch = comm::Chan(&po);
453-
comm::send(setup_ch, ch);
454-
f(move po);
455-
}
456-
comm::recv(setup_po)
457-
}
458-
459-
/**
460-
* Runs a new task, setting up communication in both directions
461-
*/
462-
fn spawn_conversation<A: Owned, B: Owned>
463-
(f: fn~(comm::Port<A>, comm::Chan<B>))
464-
-> (comm::Port<B>, comm::Chan<A>) {
465-
let from_child = comm::Port();
466-
let to_parent = comm::Chan(&from_child);
467-
let to_child = do self.spawn_listener |move f, from_parent| {
468-
f(from_parent, to_parent)
469-
};
470-
(from_child, to_child)
471-
}
472-
473436
/**
474437
* Execute a function in another task and return either the return value
475438
* of the function or result::err.
@@ -567,28 +530,6 @@ pub fn spawn_with<A:Owned>(arg: A, f: fn~(v: A)) {
567530
task().spawn_with(move arg, move f)
568531
}
569532
570-
pub fn spawn_listener<A:Owned>(f: fn~(comm::Port<A>)) -> comm::Chan<A> {
571-
/*!
572-
* Runs a new task while providing a channel from the parent to the child
573-
*
574-
* This function is equivalent to `task().spawn_listener(f)`.
575-
*/
576-
577-
task().spawn_listener(move f)
578-
}
579-
580-
pub fn spawn_conversation<A: Owned, B: Owned>
581-
(f: fn~(comm::Port<A>, comm::Chan<B>))
582-
-> (comm::Port<B>, comm::Chan<A>) {
583-
/*!
584-
* Runs a new task, setting up communication in both directions
585-
*
586-
* This function is equivalent to `task().spawn_conversation(f)`.
587-
*/
588-
589-
task().spawn_conversation(move f)
590-
}
591-
592533
pub fn spawn_sched(mode: SchedMode, f: fn~()) {
593534
/*!
594535
* Creates a new scheduler and executes a task on it
@@ -926,34 +867,6 @@ fn test_back_to_the_future_result() {
926867
let _ = task().future_result(util::ignore).future_result(util::ignore);
927868
}
928869

929-
#[test]
930-
fn test_spawn_listiner_bidi() {
931-
let po = comm::Port();
932-
let ch = comm::Chan(&po);
933-
let ch = do spawn_listener |po| {
934-
// Now the child has a port called 'po' to read from and
935-
// an environment-captured channel called 'ch'.
936-
let res: ~str = comm::recv(po);
937-
assert res == ~"ping";
938-
comm::send(ch, ~"pong");
939-
};
940-
// Likewise, the parent has both a 'po' and 'ch'
941-
comm::send(ch, ~"ping");
942-
let res: ~str = comm::recv(po);
943-
assert res == ~"pong";
944-
}
945-
946-
#[test]
947-
fn test_spawn_conversation() {
948-
let (recv_str, send_int) = do spawn_conversation |recv_int, send_str| {
949-
let input = comm::recv(recv_int);
950-
let output = int::str(input);
951-
comm::send(send_str, move output);
952-
};
953-
comm::send(send_int, 1);
954-
assert comm::recv(recv_str) == ~"1";
955-
}
956-
957870
#[test]
958871
fn test_try_success() {
959872
match do try {
@@ -1115,15 +1028,6 @@ fn test_avoid_copying_the_body_spawn() {
11151028
avoid_copying_the_body(spawn);
11161029
}
11171030

1118-
#[test]
1119-
fn test_avoid_copying_the_body_spawn_listener() {
1120-
do avoid_copying_the_body |f| {
1121-
spawn_listener(fn~(move f, _po: comm::Port<int>) {
1122-
f();
1123-
});
1124-
}
1125-
}
1126-
11271031
#[test]
11281032
fn test_avoid_copying_the_body_task_spawn() {
11291033
do avoid_copying_the_body |f| {
@@ -1133,15 +1037,6 @@ fn test_avoid_copying_the_body_task_spawn() {
11331037
}
11341038
}
11351039

1136-
#[test]
1137-
fn test_avoid_copying_the_body_spawn_listener_1() {
1138-
do avoid_copying_the_body |f| {
1139-
task().spawn_listener(fn~(move f, _po: comm::Port<int>) {
1140-
f();
1141-
});
1142-
}
1143-
}
1144-
11451040
#[test]
11461041
fn test_avoid_copying_the_body_try() {
11471042
do avoid_copying_the_body |f| {

src/librustdoc/astsrv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub fn from_file<T>(file: ~str, owner: SrvOwner<T>) -> T {
6464
fn run<T>(owner: SrvOwner<T>, source: ~str, +parse: Parser) -> T {
6565

6666
let srv_ = Srv({
67-
ch: do task::spawn_listener |move parse, po| {
67+
ch: do util::spawn_listener |move parse, po| {
6868
act(po, source, parse);
6969
}
7070
});

src/librustdoc/page_pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn run(
3939
return doc;
4040
}
4141

42-
let (result_port, page_chan) = do task::spawn_conversation
42+
let (result_port, page_chan) = do util::spawn_conversation
4343
|page_port, result_chan| {
4444
comm::send(result_chan, make_doc_from_pages(page_port));
4545
};

src/librustdoc/util.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,26 @@ impl<T: Copy> NominalOp<T>: Clone {
1717
fn clone(&self) -> NominalOp<T> { copy *self }
1818
}
1919

20+
pub fn spawn_listener<A: Owned>(
21+
+f: fn~(comm::Port<A>)) -> comm::Chan<A> {
22+
let setup_po = comm::Port();
23+
let setup_ch = comm::Chan(&setup_po);
24+
do task::spawn |move f| {
25+
let po = comm::Port();
26+
let ch = comm::Chan(&po);
27+
comm::send(setup_ch, ch);
28+
f(move po);
29+
}
30+
comm::recv(setup_po)
31+
}
32+
33+
pub fn spawn_conversation<A: Owned, B: Owned>
34+
(+f: fn~(comm::Port<A>, comm::Chan<B>))
35+
-> (comm::Port<B>, comm::Chan<A>) {
36+
let from_child = comm::Port();
37+
let to_parent = comm::Chan(&from_child);
38+
let to_child = do spawn_listener |move f, from_parent| {
39+
f(from_parent, to_parent)
40+
};
41+
(from_child, to_child)
42+
}

src/test/bench/shootout-chameneos-redux.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,19 @@ fn creature(
131131
}
132132
133133
fn rendezvous(nn: uint, set: ~[color]) {
134+
135+
pub fn spawn_listener<A: Send>(+f: fn~(comm::Port<A>)) -> comm::Chan<A> {
136+
let setup_po = comm::Port();
137+
let setup_ch = comm::Chan(&setup_po);
138+
do task::spawn |move f| {
139+
let po = comm::Port();
140+
let ch = comm::Chan(&po);
141+
comm::send(setup_ch, ch);
142+
f(move po);
143+
}
144+
comm::recv(setup_po)
145+
}
146+
134147
// these ports will allow us to hear from the creatures
135148
let from_creatures: comm::Port<creature_info> = comm::Port();
136149
let from_creatures_log: comm::Port<~str> = comm::Port();
@@ -146,7 +159,7 @@ fn rendezvous(nn: uint, set: ~[color]) {
146159
// give us a channel to talk to each
147160
let ii = ii;
148161
let col = *col;
149-
do task::spawn_listener |from_rendezvous, move ii, move col| {
162+
do spawn_listener |from_rendezvous, move ii, move col| {
150163
creature(ii, col, from_rendezvous, to_rendezvous,
151164
to_rendezvous_log);
152165
}

0 commit comments

Comments
 (0)