Skip to content

Commit d143528

Browse files
authored
Minor fix-ups to the async section. (#566)
These address some comments in #496.
1 parent 87f1976 commit d143528

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

src/async/control-flow/select.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ async fn main() {
6969
* Try adding a deadline to the race, demonstrating selecting different sorts of
7070
futures.
7171

72-
* Note that `select!` consumes the futures it is given, and is easiest to use
73-
when every execution of `select!` creates new futures.
72+
* Note that `select!` moves the values it is given. It is easiest to use
73+
when every execution of `select!` creates new futures. An alternative is to
74+
pass `&mut future` instead of the future itself, but this can lead to
75+
issues, further discussed in the pinning slide.
7476

7577
</details>

src/async/pitfalls/async-traits.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ async fn main() {
4848

4949
<details>
5050

51-
* The difficulty with `async trait` is in that the resulting `Future` does not
52-
have a size known at compile time, because the size of the `Future` depends
53-
on the implementation.
54-
5551
* `async_trait` is easy to use, but note that it's using heap allocations to
56-
achieve this, and solve the unknow size problem above. This heap allocation
57-
has performance overhead.
52+
achieve this. This heap allocation has performance overhead.
53+
54+
* The challenges in language support for `async trait` are deep Rust and
55+
probably not worth describing in-depth. Niko Matsakis did a good job of
56+
explaining them in [this
57+
post](https://smallcultfollowing.com/babysteps/blog/2019/10/26/async-fn-in-traits-are-hard/)
58+
if you are interested in digging deeper.
5859

5960
* Try creating a new sleeper struct that will sleep for a random amount of time
6061
and adding it to the Vec.

src/async/pitfalls/pin.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ async fn main() {
103103
iteration (a fused future would help with this). Update to reset
104104
`timeout_fut` every time it expires.
105105
106-
* Box allocates on the heap. In some cases, `tokio::pin!` is also an option, but
106+
* Box allocates on the heap. In some cases, `std::pin::pin!` (only recently
107+
stabilized, with older code often using `tokio::pin!`) is also an option, but
107108
that is difficult to use for a future that is reassigned.
109+
108110
* Another alternative is to not use `pin` at all but spawn another task that will send to a `oneshot` channel every 100ms.
109111
110112
</details>

src/async/tasks.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Tasks
22

3-
Runtimes have the concept of a "Task", similar to a thread but much
3+
Runtimes have the concept of a "task", similar to a thread but much
44
less resource-intensive.
55

6-
A Task has a single top-level Future which the executor polls to make progress.
6+
A task has a single top-level future which the executor polls to make progress.
77
That future may have one or more nested futures that its `poll` method polls,
88
corresponding loosely to a call stack. Concurrency within a task is possible by
99
polling multiple child futures, such as racing a timer and an I/O operation.

src/exercises/day-4/async.md

-3
This file was deleted.

0 commit comments

Comments
 (0)