@@ -196,7 +196,7 @@ When complete, `make install` will place the following programs into
196196` /usr/local/bin ` :
197197
198198 * ` rustc ` , the Rust compiler
199- * ` rustdoc ` , the API-documentation tool
199+ * ` rustdoc ` , the API-documentation tool
200200 * ` cargo ` , the Rust package manager
201201
202202[ wiki-get-started ] : https://github.com/mozilla/rust/wiki/Note-getting-started-developing-Rust
@@ -2960,7 +2960,11 @@ do spawn {
29602960~~~~
29612961
29622962This child will perform the expensive computation send the result
2963- over the channel. Finally, the parent continues by performing
2963+ over the channel. (Under the hood, ` chan ` was captured by the
2964+ closure that forms the body of the child task. This capture is
2965+ allowed because channels are sendable.)
2966+
2967+ Finally, the parent continues by performing
29642968some other expensive computation and then waiting for the child's result
29652969to arrive on the port:
29662970
@@ -2978,10 +2982,10 @@ let result = port.recv();
29782982
29792983A very common thing to do is to spawn a child task where the parent
29802984and child both need to exchange messages with each
2981- other. The function ` task::spawn_listener () ` supports this pattern. We'll look
2982- briefly at how it is used.
2985+ other. The function ` task::spawn_conversation () ` supports this pattern.
2986+ We'll look briefly at how it is used.
29832987
2984- To see how ` spawn_listener ()` works, we will create a child task
2988+ To see how ` spawn_conversation ()` works, we will create a child task
29852989that receives ` uint ` messages, converts them to a string, and sends
29862990the string in response. The child terminates when ` 0 ` is received.
29872991Here is the function that implements the child task:
@@ -3006,11 +3010,11 @@ loops, reading from the `from_parent` port and then sending its
30063010response to the ` to_parent ` channel. The actual response itself is
30073011simply the strified version of the received value,
30083012` uint::to_str(value) ` .
3009-
3013+
30103014Here is the code for the parent task:
30113015
30123016~~~~
3013- # import task::{spawn_listener };
3017+ # import task::{spawn_conversation };
30143018# import comm::{chan, port, methods};
30153019# fn stringifier(from_parent: comm::port<uint>,
30163020# to_parent: comm::chan<~str>) {
@@ -3020,32 +3024,30 @@ Here is the code for the parent task:
30203024# }
30213025# fn main() {
30223026
3023- let from_child = port();
3024- let to_parent = from_child.chan();
3025- let to_child = do spawn_listener |from_parent| {
3027+ let (from_child, to_child) = do spawn_conversation |from_parent, to_parent| {
30263028 stringifier(from_parent, to_parent);
30273029};
30283030
30293031to_child.send(22u);
30303032assert from_child.recv() == ~"22";
30313033
30323034to_child.send(23u);
3033- assert from_child.recv() == ~"23";
3034-
30353035to_child.send(0u);
3036+
3037+ assert from_child.recv() == ~"23";
30363038assert from_child.recv() == ~"0";
30373039
30383040# }
30393041~~~~
30403042
3041- The parent first sets up a port to receive data from and a channel
3042- that the child can use to send data to that port. The call to
3043- ` spawn_listener() ` will spawn the child task, providing it with a port
3044- on which to receive data from its parent, and returning to the parent
3045- the associated channel. Finally, the closure passed to
3046- ` spawn_listener() ` that forms the body of the child task captures the
3047- ` to_parent ` channel in its environment, so both parent and child
3048- can send and receive data to and from the other .
3043+ The parent task calls ` spawn_conversation ` with a function that takes
3044+ a ` from_parent ` port and a ` to_parent ` channel. In return, it gets a
3045+ ` from_child ` channel and a ` to_child ` port. As a result, both parent
3046+ and child can send and receive data to and from the other.
3047+
3048+ ` spawn_conversation `
3049+ will create two port/channel pairs, passing one set to the child task
3050+ and returning the other set to the caller .
30493051
30503052# Testing
30513053
0 commit comments