updated intro
This commit is contained in:
@@ -5,9 +5,12 @@ This book aims to explain `Futures` in Rust using an example driven approach.
|
|||||||
The goal is to get a better understanding of `Futures` by implementing a toy
|
The goal is to get a better understanding of `Futures` by implementing a toy
|
||||||
`Reactor`, a very simple `Executor` and our own `Futures`.
|
`Reactor`, a very simple `Executor` and our own `Futures`.
|
||||||
|
|
||||||
We'll start off solving a small problem without `Futures`, `Wakers` or async/await
|
We'll start off a bit untraditionally. Instead of deferring some of the details about what's
|
||||||
and then gradually adapt our example so it implements all these concepts, and
|
special about futures in Rust we try to tackle that head on first. We'll be as brief as possible,
|
||||||
can be solved using the executor provided by both `tokio` and `async_str`.
|
but as thorough as needed. I findt that implementing and understanding `Futures` is a lot easier
|
||||||
|
then. Actually, most questions will be answered up front.
|
||||||
|
|
||||||
|
We'll end up with futures that can run an any executor like `tokio` and `async_str`.
|
||||||
|
|
||||||
In the end I've made some reader excercises you can do if you want to fix some
|
In the end I've made some reader excercises you can do if you want to fix some
|
||||||
of the most glaring ommissions and shortcuts we took and create a slightly better
|
of the most glaring ommissions and shortcuts we took and create a slightly better
|
||||||
@@ -17,7 +20,7 @@ example yourself.
|
|||||||
|
|
||||||
That's a valid question. There are many good resources and examples already. First
|
That's a valid question. There are many good resources and examples already. First
|
||||||
of all, this book will point you to some background information that I have found
|
of all, this book will point you to some background information that I have found
|
||||||
very valuable to get an understanding of concurrent programming in general.
|
very valuable, especially `Generators` and stackless coroutines.
|
||||||
|
|
||||||
I find that many discussions arise, not because `Futures` is a hard concept to
|
I find that many discussions arise, not because `Futures` is a hard concept to
|
||||||
grasp, but that concurrent programming is a hard concept in general.
|
grasp, but that concurrent programming is a hard concept in general.
|
||||||
|
|||||||
@@ -22,5 +22,11 @@ Now learning these concepts by studying futures is making it much harder than
|
|||||||
it needs to be, so go on and read these chapters. I'll be right here when
|
it needs to be, so go on and read these chapters. I'll be right here when
|
||||||
you're back.
|
you're back.
|
||||||
|
|
||||||
However, if you feel that you have the basics covered, then go right on. Let's
|
However, if you feel that you have the basics covered, then go right on. The concepts we need to
|
||||||
get moving!
|
learn are:
|
||||||
|
|
||||||
|
1. Trait Objects and fat pointers
|
||||||
|
2. Generators/stackless coroutines
|
||||||
|
3. Pinning, what it is and why we need it
|
||||||
|
|
||||||
|
Let's get moving!
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
# Generators and Pin
|
# Generators
|
||||||
|
|
||||||
So the second difficult part that there seems to be a lot of questions about
|
So the second difficult part that there seems to be a lot of questions about
|
||||||
is Generators and the `Pin` type.
|
is Generators and the `Pin` type. Since they're related we'll start off by
|
||||||
|
undertanding generators first. By doing that we'll soon get to see why
|
||||||
## Generators
|
we need to be able to "pin" some data to a fixed location in memory and
|
||||||
|
get an introduction to `Pin` as well.
|
||||||
|
|
||||||
|
|
||||||
>**Relevant for:**
|
>**Relevant for:**
|
||||||
@@ -29,8 +30,8 @@ I've written about green threads before. Go check out
|
|||||||
[Green Threads Explained in 200 lines of Rust][greenthreads] if you're interested.
|
[Green Threads Explained in 200 lines of Rust][greenthreads] if you're interested.
|
||||||
|
|
||||||
Green threads uses the same mechanisms as an OS does by creating a thread for
|
Green threads uses the same mechanisms as an OS does by creating a thread for
|
||||||
each task, setting up a stack and forcing the CPU to save it's state and jump
|
each task, setting up a stack, save the CPU's state and jump
|
||||||
from one task(thread) to another. We yield control to the scheduler which then
|
from one task(thread) to another by doing a "context switch". We yield control to the scheduler which then
|
||||||
continues running a different task.
|
continues running a different task.
|
||||||
|
|
||||||
Rust had green threads once, but they were removed before it hit 1.0. The state
|
Rust had green threads once, but they were removed before it hit 1.0. The state
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
- [Introduction](./0_0_introduction.md)
|
- [Introduction](./0_0_introduction.md)
|
||||||
- [Some background information](./1_0_background_information.md)
|
- [Some background information](./1_0_background_information.md)
|
||||||
- [Trait objects and fat pointers](./1_1_trait_objects.md)
|
- [Trait objects and fat pointers](./1_1_trait_objects.md)
|
||||||
- [Generators and Pin](./1_2_generators_pin.md)
|
- [Generators and Pin](./1_2_generators_pin.md)
|
||||||
- [Pin](./1_3_pin.md)
|
- [Pin](./1_3_pin.md)
|
||||||
- [The main example](./2_0_future_example.md)
|
- [The main example](./2_0_future_example.md)
|
||||||
- [Bonus 1: concurrent futures](2_1_concurrent_futures.md)
|
- [Bonus 1: concurrent futures](2_1_concurrent_futures.md)
|
||||||
|
|||||||
Reference in New Issue
Block a user