Skip to content

Commit da44ec5

Browse files
authored
Merge pull request #51 from luizirber/patch-1
Fix links in concepts/futures.md
2 parents 1040a25 + 43d0cd8 commit da44ec5

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

docs/src/concepts/futures.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Note how we avoided any word like *"thread"*, but instead opted for "computation
1515

1616
`Send` and `Sync` can be composed in interesting fashions, but that's beyond the scope here. You can find examples in the [Rust Book][rust-book-sync].
1717

18+
[rust-book-sync]: https://doc.rust-lang.org/stable/book/ch16-04-extensible-concurrency-sync-and-send.html
19+
1820
To sum up: Rust gives us the ability to safely abstract over important properties of concurrent programs: their data sharing. It does so in a very lightweight fashion: the language itself only knows about the two markers `Send` and `Sync` and helps us a little by deriving them itself, when possible. The rest is a library concern.
1921

2022
## An easy view of computation
@@ -26,7 +28,7 @@ While computation is a subject to write a whole [book](https://computationbook.c
2628
- they either run to succession and yield a result or they can yield an error
2729
## Deferring computation
2830

29-
As mentioned above `Send` and `Sync` are about data. But programs are not only about data, they also talk about *computing* the data. And that's what \[Futures\][futures] do. We are going to have a close look at how that works in the next chapter. Let's look at what Futures allow us to express, in English. Futures go from this plan:
31+
As mentioned above `Send` and `Sync` are about data. But programs are not only about data, they also talk about *computing* the data. And that's what [`Futures`][futures] do. We are going to have a close look at how that works in the next chapter. Let's look at what Futures allow us to express, in English. Futures go from this plan:
3032

3133
- Do X
3234
- If X succeeds, do Y
@@ -38,6 +40,8 @@ towards
3840

3941
Remember the talk about "deferred computation" in the intro? That's all it is. Instead of telling the computer what to execute and decide upon *now*, you tell it what to start doing and how to react on potential events the... well... `Future`.
4042

43+
[futures]: https://doc.rust-lang.org/std/future/trait.Future.html
44+
4145
## Orienting towards the beginning
4246

4347
Let's have a look at a simple function, specifically the return value:
@@ -75,8 +79,8 @@ What we are searching is something that represents ongoing work towards a result
7579
Ignore `Pin` and `Context` for now, you don't need them for high-level understanding. Looking at it closely, we see the following: it is generic over the `Output`. It provides a function called `poll`, which allows us to check on the state of the current computation.
7680
Every call to `poll()` can result in one of these two cases:
7781

78-
1. The future is done, `poll` will return `[Poll::Ready](https://doc.rust-lang.org/std/task/enum.Poll.html#variant.Ready)`
79-
2. The future has not finished executing, it will return `[Poll::Pending](https://doc.rust-lang.org/std/task/enum.Poll.html#variant.Pending)`
82+
1. The future is done, `poll` will return [`Poll::Ready`](https://doc.rust-lang.org/std/task/enum.Poll.html#variant.Ready)
83+
2. The future has not finished executing, it will return [`Poll::Pending`](https://doc.rust-lang.org/std/task/enum.Poll.html#variant.Pending)
8084

8185
This allows us to externally check if a `Future` has finished doing its work, or is finally done and can give us the value. The most simple way (but not efficient) would be to just constantly poll futures in a loop. There's optimistions here, and this is what a good runtime is does for you.
8286
Note that calling `poll` after case 1 happened may result in confusing behaviour. See the [futures-docs](https://doc.rust-lang.org/std/future/trait.Future.html) for details.

0 commit comments

Comments
 (0)