Skip to content

Commit

Permalink
Update tasks guide: SharedChan as been removed
Browse files Browse the repository at this point in the history
The code examples are up to date, but the surrounding explanations are not.
  • Loading branch information
ehsanul committed Feb 17, 2014
1 parent c848906 commit b9c476b
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/doc/guide-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ spawn(proc() {
});
~~~

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

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

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

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

5 comments on commit b9c476b

@bors
Copy link
Contributor

@bors bors commented on b9c476b Feb 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at ehsanul@b9c476b

@bors
Copy link
Contributor

@bors bors commented on b9c476b Feb 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging ehsanul/rust/remove-shared-chan-tasks-guide = b9c476b into auto

@bors
Copy link
Contributor

@bors bors commented on b9c476b Feb 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ehsanul/rust/remove-shared-chan-tasks-guide = b9c476b merged ok, testing candidate = 1e60084

@bors
Copy link
Contributor

@bors bors commented on b9c476b Feb 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on b9c476b Feb 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 1e60084

Please sign in to comment.