add various notes, change some wording - #402
Conversation
Deploying ferrous-systems-rust-training with
|
| Latest commit: |
be16011
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://74a41923.ferrous-systems-rust-training.pages.dev |
| Branch Preview URL: | https://more-async-slide-improvement.ferrous-systems-rust-training.pages.dev |
|
|
||
| - Imperative: Statements in synchronous code are just executed step-by-step. | ||
|
|
||
| ## Async language support |
There was a problem hiding this comment.
this is a new slide. I think the auto-generation of state machines is a fact worth mentioning?
In embedded, we commonly replace annoying state machines using async, which is really nice.
| * sync programming often has imperative behaviour | ||
| * async programming is about constructing a process at runtime and then executing it | ||
| * this process is called the "futures tree" | ||
| * async programming is about constructing an execution plan and then letting an executor run it |
There was a problem hiding this comment.
is "execution plan" something that makes sense here?
There was a problem hiding this comment.
not really; the executor doesn't know ahead of time what's going to be run, and the async task can spawn more tasks at runtime. see https://jyn.dev/what-is-a-build-system-anyway/#applicative-and-monadic-structure for more discussion.
| ## Async | ||
|
|
||
| * Built from important "building blocks" | ||
| * Built from important building blocks, which are partially baked into the language |
There was a problem hiding this comment.
wondering why "building blocks" was in quotes, was there a specific reason? I also mentioned that the async/await is partially baked into the language. is this superfluous?
| * sync programming often has imperative behaviour | ||
| * async programming is about constructing a process at runtime and then executing it | ||
| * this process is called the "futures tree" | ||
| * async programming is an abstraction that allows developers to define pausing points where |
There was a problem hiding this comment.
Paraphrased from https://doc.rust-lang.org/book/ch17-00-async-await.html. I think this is an excellent simplification for explaining the difference between sync / async.
There was a problem hiding this comment.
i would phrase this as "waiting points" to closer parallel the await syntax, or "yield points" to parallel your wording below.
dcb9e74 to
4f98604
Compare
99f0752 to
44eaaa2
Compare
| Note: | ||
|
|
||
| - function must be `async` so `await` can be used inside it. | ||
| - The code between two `await`ion points has a regular synchronous flow. |
There was a problem hiding this comment.
I think this might be worth mentioning? at awaition points, the executor might pause and do some other pending work, but the flow between the awaition points is still regular synchronous code.
There was a problem hiding this comment.
yes, this is very worth mentioning. you might be interested in https://ryhl.io/blog/async-what-is-blocking/, particularly the bit that says "other tasks on the same runtime will stop running until the thread is no longer being blocked".
jyn514
left a comment
There was a problem hiding this comment.
I can't comment on why the existing wording is there, but I've done a pass confirming factual changes. This looks good overall :) just small wording suggestions.
| * sync programming often has imperative behaviour | ||
| * async programming is about constructing a process at runtime and then executing it | ||
| * this process is called the "futures tree" | ||
| * async programming is an abstraction that allows developers to define pausing points where |
There was a problem hiding this comment.
i would phrase this as "waiting points" to closer parallel the await syntax, or "yield points" to parallel your wording below.
|
|
||
| Note: | ||
|
|
||
| - Imperative: Statements in synchronous code are just executed step-by-step. |
There was a problem hiding this comment.
| - Imperative: Statements in synchronous code are just executed step-by-step. | |
| - Imperative: Statements in single-threaded synchronous code are always executed in order. Statements in asynchronous code may be executed out-of-order, even in a single thread. |
There was a problem hiding this comment.
what is the "out-of-order" related to here? because some processors can re-order or perform "out-of-order" execution on synchronous code as well, right?
| ## Async language support | ||
|
|
||
| * `async` functions can define yield points where the execution can be paused, represented by | ||
| `await`ion points. |
There was a problem hiding this comment.
| `await`ion points. | |
| `.await` syntax. |
| Note: | ||
|
|
||
| - function must be `async` so `await` can be used inside it. | ||
| - The code between two `await`ion points has a regular synchronous flow. |
There was a problem hiding this comment.
yes, this is very worth mentioning. you might be interested in https://ryhl.io/blog/async-what-is-blocking/, particularly the bit that says "other tasks on the same runtime will stop running until the thread is no longer being blocked".
|
|
||
| Note: | ||
|
|
||
| - Helpful mental model: A `async` function is a regular synchronous functions that returns a `Future`. |
There was a problem hiding this comment.
💯. effectively async fn is a promise to the reader "no synchronous work happens before i return a Future".
|
|
||
| Note: | ||
|
|
||
| - Alternative wording: A future can be resolved or polled to completion. |
There was a problem hiding this comment.
"resolved or polled to completion" makes it sound like these are two different things, but they're the same. i would say "futures can be resolved by polling them to completion, or canceled by dropping them".
| - On full operating systems, mechanisms like `epoll` are used | ||
| - On embedded systems, interrupts are used to advance or complete operations |
There was a problem hiding this comment.
this mingles implementation details with your runtime environment. you can have a hosted system that uses Unix signals for progress, and you can have an embedded system that uses spin-loops to poll without needing interrupts.
There was a problem hiding this comment.
maybe still useful to keep them as examples?
There was a problem hiding this comment.
👍 examples seem good, as long as you make it clear that hosted/embedded is independent of polling/event-wakers
There was a problem hiding this comment.
Okay, I updated this again. Considering that most use-cases will use an event driven mechanism, what do you think about the current version?
| - On full operating systems, OS mechanisms like `epoll`. | ||
| - On embedded systems, interrupts to advance or complete operations. |
There was a problem hiding this comment.
this still confuses polling/event-driven with hosted/embedded. i would prefer to state the two axes separately.
No description provided.