Skip to content

Commit 1e60084

Browse files
committed
auto merge of #12342 : ehsanul/rust/remove-shared-chan-tasks-guide, r=alexcrichton
The code examples are up to date, but the surrounding explanations are not.
2 parents b0ce960 + b9c476b commit 1e60084

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/doc/guide-tasks.md

+7-11
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ spawn(proc() {
226226
});
227227
~~~
228228

229-
Instead we can use a `SharedChan`, a type that allows a single
230-
`Chan` to be shared by multiple senders.
229+
Instead we can clone the `chan`, which allows for multiple senders.
231230

232231
~~~
233232
# use std::task::spawn;
@@ -246,16 +245,13 @@ let result = port.recv() + port.recv() + port.recv();
246245
# fn some_expensive_computation(_i: uint) -> int { 42 }
247246
~~~
248247

249-
Here we transfer ownership of the channel into a new `SharedChan` value. Like
250-
`Chan`, `SharedChan` is a non-copyable, owned type (sometimes also referred to
251-
as an *affine* or *linear* type). Unlike with `Chan`, though, the programmer
252-
may duplicate a `SharedChan`, with the `clone()` method. A cloned
253-
`SharedChan` produces a new handle to the same channel, allowing multiple
254-
tasks to send data to a single port. Between `spawn`, `Chan` and
255-
`SharedChan`, we have enough tools to implement many useful concurrency
256-
patterns.
248+
Cloning a `Chan` produces a new handle to the same channel, allowing multiple
249+
tasks to send data to a single port. It also upgrades the channel internally in
250+
order to allow this functionality, which means that channels that are not
251+
cloned can avoid the overhead required to handle multiple senders. But this
252+
fact has no bearing on the channel's usage: the upgrade is transparent.
257253

258-
Note that the above `SharedChan` example is somewhat contrived since
254+
Note that the above cloning example is somewhat contrived since
259255
you could also simply use three `Chan` pairs, but it serves to
260256
illustrate the point. For reference, written with multiple streams, it
261257
might look like the example below.

0 commit comments

Comments
 (0)