mirror of
https://github.com/google/comprehensive-rust.git
synced 2024-11-21 13:25:53 +02:00
Links in channel pages (#2441)
This commit is contained in:
parent
ad7ef2e50a
commit
ab78a9e6b8
@ -4,7 +4,7 @@ minutes: 8
|
||||
|
||||
# Bounded Channels
|
||||
|
||||
With bounded (synchronous) channels, `send` can block the current thread:
|
||||
With bounded (synchronous) channels, [`send()`] can block the current thread:
|
||||
|
||||
```rust,editable
|
||||
use std::sync::mpsc;
|
||||
@ -32,12 +32,15 @@ fn main() {
|
||||
|
||||
<details>
|
||||
|
||||
- Calling `send` will block the current thread until there is space in the
|
||||
- Calling `send()` will block the current thread until there is space in the
|
||||
channel for the new message. The thread can be blocked indefinitely if there
|
||||
is nobody who reads from the channel.
|
||||
- A call to `send` will abort with an error (that is why it returns `Result`) if
|
||||
the channel is closed. A channel is closed when the receiver is dropped.
|
||||
- A call to `send()` will abort with an error (that is why it returns `Result`)
|
||||
if the channel is closed. A channel is closed when the receiver is dropped.
|
||||
- A bounded channel with a size of zero is called a "rendezvous channel". Every
|
||||
send will block the current thread until another thread calls `recv`.
|
||||
send will block the current thread until another thread calls [`recv()`].
|
||||
|
||||
</details>
|
||||
|
||||
[`send()`]: https://doc.rust-lang.org/std/sync/mpsc/struct.SyncSender.html#method.send
|
||||
[`recv()`]: https://doc.rust-lang.org/std/sync/mpsc/struct.Receiver.html#method.recv
|
||||
|
@ -4,8 +4,8 @@ minutes: 9
|
||||
|
||||
# Senders and Receivers
|
||||
|
||||
Rust channels have two parts: a `Sender<T>` and a `Receiver<T>`. The two parts
|
||||
are connected via the channel, but you only see the end-points.
|
||||
Rust channels have two parts: a [`Sender<T>`] and a [`Receiver<T>`]. The two
|
||||
parts are connected via the channel, but you only see the end-points.
|
||||
|
||||
```rust,editable
|
||||
use std::sync::mpsc;
|
||||
@ -27,10 +27,16 @@ fn main() {
|
||||
|
||||
<details>
|
||||
|
||||
- `mpsc` stands for Multi-Producer, Single-Consumer. `Sender` and `SyncSender`
|
||||
- [`mpsc`] stands for Multi-Producer, Single-Consumer. `Sender` and `SyncSender`
|
||||
implement `Clone` (so you can make multiple producers) but `Receiver` does
|
||||
not.
|
||||
- `send()` and `recv()` return `Result`. If they return `Err`, it means the
|
||||
- [`send()`] and [`recv()`] return `Result`. If they return `Err`, it means the
|
||||
counterpart `Sender` or `Receiver` is dropped and the channel is closed.
|
||||
|
||||
</details>
|
||||
|
||||
[`Sender<T>`]: https://doc.rust-lang.org/std/sync/mpsc/struct.Sender.html
|
||||
[`Receiver<T>`]: https://doc.rust-lang.org/std/sync/mpsc/struct.Receiver.html
|
||||
[`send()`]: https://doc.rust-lang.org/std/sync/mpsc/struct.Sender.html#method.send
|
||||
[`recv()`]: https://doc.rust-lang.org/std/sync/mpsc/struct.Receiver.html#method.recv
|
||||
[`mpsc`]: https://doc.rust-lang.org/std/sync/mpsc/index.html
|
||||
|
@ -4,7 +4,7 @@ minutes: 2
|
||||
|
||||
# Unbounded Channels
|
||||
|
||||
You get an unbounded and asynchronous channel with `mpsc::channel()`:
|
||||
You get an unbounded and asynchronous channel with [`mpsc::channel()`]:
|
||||
|
||||
```rust,editable
|
||||
use std::sync::mpsc;
|
||||
@ -29,3 +29,5 @@ fn main() {
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
[`mpsc::channel()`]: https://doc.rust-lang.org/std/sync/mpsc/fn.channel.html
|
||||
|
Loading…
Reference in New Issue
Block a user