finished book!!!!!!
This commit is contained in:
@@ -150,45 +150,56 @@
|
||||
<div id="content" class="content">
|
||||
<main>
|
||||
<h1><a class="header" href="#futures-explained-in-200-lines-of-rust" id="futures-explained-in-200-lines-of-rust">Futures Explained in 200 Lines of Rust</a></h1>
|
||||
<p>This book aims to explain <code>Futures</code> in Rust using an example driven approach.</p>
|
||||
<p>The goal is to get a better understanding of "async" in Rust by creating a toy
|
||||
runtime consisting of a <code>Reactor</code> and an <code>Executor</code>, and our own futures which
|
||||
we can run concurrently.</p>
|
||||
<p>We'll start off a bit differently than most other explanations. Instead of
|
||||
deferring some of the details about what <code>Futures</code> are and how they're
|
||||
implemented, we tackle that head on first.</p>
|
||||
<p>I learn best when I can take basic understandable concepts and build piece by
|
||||
piece of these basic building blocks until everything is understood. This way,
|
||||
most questions will be answered and explored up front and the conclusions later
|
||||
on seems natural.</p>
|
||||
<p>I've limited myself to a 200 line main example so that we need keep
|
||||
this fairly brief.</p>
|
||||
<p>In the end I've made some reader exercises you can do if you want to fix some
|
||||
of the most glaring omissions and shortcuts we took and create a slightly better
|
||||
example yourself.</p>
|
||||
<p>This book aims to explain <code>Futures</code> in Rust using an example driven approach,
|
||||
exploring why they're designed the way they are, the alternatives and how
|
||||
they work.</p>
|
||||
<p>Going into the level of detail I do in this book is not needed to use futures
|
||||
or async/await in Rust. It's for the curious out there that want to know <em>how</em>
|
||||
it all works.</p>
|
||||
<h2><a class="header" href="#what-this-book-covers" id="what-this-book-covers">What this book covers</a></h2>
|
||||
<p>This book will try to explain everything you might wonder about up until the
|
||||
topic of different types of executors and runtimes. We'll just implement a very
|
||||
simple runtime in this book introducing some concepts but it's enough to get
|
||||
started.</p>
|
||||
<p><a href="https://github.com/stjepang">Stjepan Glavina</a> has made an excellent series of
|
||||
articles about async runtimes and executors, and if the rumors are right he's
|
||||
even working on a new async runtime that should be easy enough to use as
|
||||
learning material.</p>
|
||||
<p>The way you should go about it is to read this book first, then continue
|
||||
reading the <a href="https://stjepang.github.io/">articles from stejpang</a> to learn more
|
||||
about runtimes and how they work, especially:</p>
|
||||
<ol>
|
||||
<li><a href="https://stjepang.github.io/2020/01/25/build-your-own-block-on.html">Build your own block_on()</a></li>
|
||||
<li><a href="https://stjepang.github.io/2020/01/31/build-your-own-executor.html">Build your own executor</a></li>
|
||||
</ol>
|
||||
<p>I've limited myself to a 200 line main example (hence the title) to limit the
|
||||
scope and introduce an example that can easily be explored further.</p>
|
||||
<p>However, there is a lot to digest and it's not what I would call easy, but we'll
|
||||
take everything step by step so get a cup of tea and relax. </p>
|
||||
<p>I hope you enjoy the ride.</p>
|
||||
<blockquote>
|
||||
<p>This book is developed in the open, and contributions are welcome. You'll find
|
||||
<a href="https://github.com/cfsamson/books-futures-explained">the repository for the book itself here</a>. The final example which
|
||||
you can clone, fork or copy <a href="https://github.com/cfsamson/examples-futures">can be found here</a></p>
|
||||
you can clone, fork or copy <a href="https://github.com/cfsamson/examples-futures">can be found here</a>. Any suggestions
|
||||
or improvements can be filed as a PR or in the issue tracker for the book.</p>
|
||||
</blockquote>
|
||||
<h2><a class="header" href="#what-does-this-book-give-you-that-isnt-covered-elsewhere" id="what-does-this-book-give-you-that-isnt-covered-elsewhere">What does this book give you that isn't covered elsewhere?</a></h2>
|
||||
<p>There are many good resources and examples already. First
|
||||
of all, this book will focus on <code>Futures</code> and <code>async/await</code> specifically and
|
||||
not in the context of any specific runtime.</p>
|
||||
<p>Secondly, I've always found small runnable examples very exiting to learn from.
|
||||
Thanks to <a href="https://github.com/rust-lang/mdBook">Mdbook</a> the examples can even be edited and explored further
|
||||
by uncommenting certain lines or adding new ones yourself. I use that quite a
|
||||
but throughout so keep an eye out when reading through editable code segments.</p>
|
||||
<p>It's all code that you can download, play with and learn from.</p>
|
||||
<p>We'll and end up with an understandable example including a <code>Future</code>
|
||||
implementation, an <code>Executor</code> and a <code>Reactor</code> in less than 200 lines of code.
|
||||
We don't rely on any dependencies or real I/O which means it's very easy to
|
||||
explore further and try your own ideas.</p>
|
||||
<h2><a class="header" href="#reader-exercises-and-further-reading" id="reader-exercises-and-further-reading">Reader exercises and further reading</a></h2>
|
||||
<p>In the last <a href="conclusion.html">chapter</a> I've taken the liberty to suggest some
|
||||
small exercises if you want to explore a little further.</p>
|
||||
<p>This book is also the fourth book I have written about concurrent programming
|
||||
in Rust. If you like it, you might want to check out the others as well:</p>
|
||||
<ul>
|
||||
<li><a href="https://cfsamson.gitbook.io/green-threads-explained-in-200-lines-of-rust/">Green Threads Explained in 200 lines of rust</a></li>
|
||||
<li><a href="https://cfsamson.github.io/book-exploring-async-basics/">The Node Experiment - Exploring Async Basics with Rust</a></li>
|
||||
<li><a href="https://cfsamsonbooks.gitbook.io/epoll-kqueue-iocp-explained/">Epoll, Kqueue and IOCP Explained with Rust</a></li>
|
||||
</ul>
|
||||
<h2><a class="header" href="#credits-and-thanks" id="credits-and-thanks">Credits and thanks</a></h2>
|
||||
<p>I'll like to take the chance of thanking the people behind <code>mio</code>, <code>tokio</code>,
|
||||
<code>async_std</code>, <code>Futures</code>, <code>libc</code>, <code>crossbeam</code> and many other libraries which so
|
||||
much is built upon. Even the RFCs that much of the design is built upon is
|
||||
very well written and very helpful. So thanks!</p>
|
||||
much is built upon.</p>
|
||||
<p>A special thanks to <a href="https://github.com/jonhoo">Johnhoo</a> who was kind enough to
|
||||
give me some feedback on an early draft of this book. He has not read the
|
||||
finished product and has in no way endorsed it, but a thanks is definitely due.</p>
|
||||
|
||||
</main>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user