Skip to content

Commit 8e121bc

Browse files
authored
Async fixes (#546)
1 parent 281a8e6 commit 8e121bc

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@
243243
- [Pitfalls](async/pitfalls.md)
244244
- [Blocking the Executor](async/pitfalls/blocking-executor.md)
245245
- [Pin](async/pitfalls/pin.md)
246-
- [Async Traits](async/pitfalls/pin.md)
246+
- [Async Traits](async/pitfalls/async-traits.md)
247247
- [Exercises](exercises/day-4/async.md)
248248

249249
# Final Words

src/async.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ limited number of threads. This is because the per-task overhead is typically
77
very low and operating systems provide primitives for efficiently identifying
88
I/O that is able to proceed.
99

10-
Rust's asynchronous operation is based around "futures", which represent work
11-
that may be completed in the future. Futures are "polled" until they signal that
10+
Rust's asynchronous operation is based on "futures", which represent work that
11+
may be completed in the future. Futures are "polled" until they signal that
1212
they are complete.
1313

1414
Futures are polled by an async runtime, and several different runtimes are

src/async/channels.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ async fn ping_handler(mut input: Receiver<()>) {
1818
async fn main() {
1919
let (sender, receiver) = mpsc::channel(32);
2020
let ping_handler_task = tokio::spawn(ping_handler(receiver));
21-
for _ in 0..10 {
21+
for i in 0..10 {
2222
sender.send(()).await.expect("Failed to send ping.");
23+
println!("Sent {} pings so far.", i + 1);
2324
}
2425
2526
std::mem::drop(sender);
@@ -29,8 +30,16 @@ async fn main() {
2930

3031
<details>
3132

32-
- Overall, the interface is similar to the `sync` channels as seen in the [morning class](concurrency/channels.md).
33-
- The `Flume` crate has channels that implement both `sync` and `async` `send` and `recv`. This can be convenient for complex application with both IO and heavy CPU processing tasks.
34-
- What makes working with `async` channels preferable is the ability to combine them with other `future`s to combine them and create complex control flow.
33+
* Change the channel size to `3` and see how it affects the execution.
34+
35+
* Overall, the interface is similar to the `sync` channels as seen in the
36+
[morning class](concurrency/channels.md).
37+
38+
* The `Flume` crate has channels that implement both `sync` and `async` `send`
39+
and `recv`. This can be convenient for complex application with both IO and
40+
heavy CPU processing tasks.
41+
42+
* What makes working with `async` channels preferable is the ability to combine
43+
them with other `future`s to combine them and create complex control flow.
3544

3645
</details>

src/async/control-flow.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Futures Control Flow
22

3-
Futures can be combined together to produce concurrent compute flow graphs. We will cover multiple common operations:
3+
Futures can be combined together to produce concurrent compute flow graphs. We
4+
will cover multiple common operations:
45

56
----
67

src/async/futures.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ async fn count_to(count: i32) -> i32 {
1515
1616
#[tokio::main]
1717
async fn main() {
18-
let _: () = count_to(13);
18+
println!("Final count is: {}!", count_to(13).await);
19+
20+
// Uncomment the following line to see the return type of the async call.
21+
// let _: () = count_to(13);
22+
1923
}
2024
```
2125

@@ -49,10 +53,6 @@ block to pause until that Future is ready, and then evaluates to its output.
4953

5054
<details>
5155

52-
* Run the example and look at the error message. `_: () = ..` is a common
53-
technique for getting the type of an expression. Try adding a `.await` in
54-
`main`.
55-
5656
* The `Future` and `Poll` types are conceptually quite simple, and implemented as
5757
such in `std::task`.
5858

0 commit comments

Comments
 (0)