File tree 5 files changed +16
-14
lines changed
5 files changed +16
-14
lines changed Original file line number Diff line number Diff line change @@ -69,7 +69,9 @@ async fn main() {
69
69
* Try adding a deadline to the race, demonstrating selecting different sorts of
70
70
futures.
71
71
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.
74
76
75
77
</details >
Original file line number Diff line number Diff line change @@ -48,13 +48,14 @@ async fn main() {
48
48
49
49
<details >
50
50
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
-
55
51
* ` 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.
58
59
59
60
* Try creating a new sleeper struct that will sleep for a random amount of time
60
61
and adding it to the Vec.
Original file line number Diff line number Diff line change @@ -103,8 +103,10 @@ async fn main() {
103
103
iteration (a fused future would help with this). Update to reset
104
104
`timeout_fut` every time it expires.
105
105
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
107
108
that is difficult to use for a future that is reassigned.
109
+
108
110
* Another alternative is to not use `pin` at all but spawn another task that will send to a `oneshot` channel every 100ms.
109
111
110
112
</details>
Original file line number Diff line number Diff line change 1
1
# Tasks
2
2
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
4
4
less resource-intensive.
5
5
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.
7
7
That future may have one or more nested futures that its ` poll ` method polls,
8
8
corresponding loosely to a call stack. Concurrency within a task is possible by
9
9
polling multiple child futures, such as racing a timer and an I/O operation.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments