mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-04-21 15:35: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
|
# Bounded Channels
|
||||||
|
|
||||||
With bounded (synchronous) channels, `send` can block the current thread:
|
With bounded (synchronous) channels, [`send()`] can block the current thread:
|
||||||
|
|
||||||
```rust,editable
|
```rust,editable
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
@ -32,12 +32,15 @@ fn main() {
|
|||||||
|
|
||||||
<details>
|
<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
|
channel for the new message. The thread can be blocked indefinitely if there
|
||||||
is nobody who reads from the channel.
|
is nobody who reads from the channel.
|
||||||
- A call to `send` will abort with an error (that is why it returns `Result`) if
|
- A call to `send()` will abort with an error (that is why it returns `Result`)
|
||||||
the channel is closed. A channel is closed when the receiver is dropped.
|
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
|
- 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>
|
</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
|
# Senders and Receivers
|
||||||
|
|
||||||
Rust channels have two parts: a `Sender<T>` and a `Receiver<T>`. The two parts
|
Rust channels have two parts: a [`Sender<T>`] and a [`Receiver<T>`]. The two
|
||||||
are connected via the channel, but you only see the end-points.
|
parts are connected via the channel, but you only see the end-points.
|
||||||
|
|
||||||
```rust,editable
|
```rust,editable
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
@ -27,10 +27,16 @@ fn main() {
|
|||||||
|
|
||||||
<details>
|
<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
|
implement `Clone` (so you can make multiple producers) but `Receiver` does
|
||||||
not.
|
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.
|
counterpart `Sender` or `Receiver` is dropped and the channel is closed.
|
||||||
|
|
||||||
</details>
|
</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
|
# Unbounded Channels
|
||||||
|
|
||||||
You get an unbounded and asynchronous channel with `mpsc::channel()`:
|
You get an unbounded and asynchronous channel with [`mpsc::channel()`]:
|
||||||
|
|
||||||
```rust,editable
|
```rust,editable
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
@ -29,3 +29,5 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
[`mpsc::channel()`]: https://doc.rust-lang.org/std/sync/mpsc/fn.channel.html
|
||||||
|
Loading…
x
Reference in New Issue
Block a user