An example of hand-written coroutines
The example we’ll use going forward is a simplified version of Rust’s asynchronous model. We’ll create and implement the following:
- Our own simplified
Future
trait - A simple HTTP client that can only make GET requests
- A task we can pause and resume implemented as a state machine
- Our own simplified
async/await
syntax calledcoroutine/wait
- A homemade preprocessor to transform our
coroutine/wait
functions into state machines the same wayasync/await
is transformed
So, to actually demystify coroutines, futures, and async/await
, we will have to make some compromises. If we didn’t, we’d end up re-implementing everything that is async/await
and futures in Rust today, which is too much for just understanding the underlying techniques and concepts.
Therefore, our example will do the following:
- Avoid error handling. If anything fails, we panic.
- Be specific and not generic. Creating...