From bd22456e448ee593a0c33ba9efb0aaef9fe5caa4 Mon Sep 17 00:00:00 2001 From: Luiz Irber Date: Fri, 16 Aug 2019 13:07:25 -0700 Subject: [PATCH 1/6] FIx rust-book-sync link --- docs/src/concepts/futures.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/src/concepts/futures.md b/docs/src/concepts/futures.md index be04cfe..185aa74 100644 --- a/docs/src/concepts/futures.md +++ b/docs/src/concepts/futures.md @@ -15,6 +15,8 @@ Note how we avoided any word like *"thread"*, but instead opted for "computation `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]. +[rust-book-sync]: https://doc.rust-lang.org/stable/book/ch16-04-extensible-concurrency-sync-and-send.html + 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. ## An easy view of computation From 43d0cd8dc8799c7b238a90fbf7b41c9ef1f343dc Mon Sep 17 00:00:00 2001 From: Luiz Irber Date: Fri, 16 Aug 2019 20:24:51 +0000 Subject: [PATCH 2/6] fix formatting and add Futures link --- docs/src/concepts/futures.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/src/concepts/futures.md b/docs/src/concepts/futures.md index 185aa74..9b5148b 100644 --- a/docs/src/concepts/futures.md +++ b/docs/src/concepts/futures.md @@ -28,7 +28,7 @@ While computation is a subject to write a whole [book](https://computationbook.c - they either run to succession and yield a result or they can yield an error ## Deferring computation -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: +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: - Do X - If X succeeds, do Y @@ -40,6 +40,8 @@ towards 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`. +[futures]: https://doc.rust-lang.org/std/future/trait.Future.html + ## Orienting towards the beginning Let's have a look at a simple function, specifically the return value: @@ -77,8 +79,8 @@ What we are searching is something that represents ongoing work towards a result 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. Every call to `poll()` can result in one of these two cases: -1. The future is done, `poll` will return `[Poll::Ready](https://doc.rust-lang.org/std/task/enum.Poll.html#variant.Ready)` -2. The future has not finished executing, it will return `[Poll::Pending](https://doc.rust-lang.org/std/task/enum.Poll.html#variant.Pending)` +1. The future is done, `poll` will return [`Poll::Ready`](https://doc.rust-lang.org/std/task/enum.Poll.html#variant.Ready) +2. The future has not finished executing, it will return [`Poll::Pending`](https://doc.rust-lang.org/std/task/enum.Poll.html#variant.Pending) 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. 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. From 77171b5f45faed07ac3347e4b16bdaeba1e5faee Mon Sep 17 00:00:00 2001 From: skorgu Date: Fri, 16 Aug 2019 16:42:21 -0400 Subject: [PATCH 3/6] Rename 'task' variable in example The collision between the 'task' variable and the 'task' import is confusing (task::block_on(task) especially). --- docs/src/concepts/tasks.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/concepts/tasks.md b/docs/src/concepts/tasks.md index a4238dd..743d578 100644 --- a/docs/src/concepts/tasks.md +++ b/docs/src/concepts/tasks.md @@ -15,7 +15,7 @@ async fn read_file(path: &str) -> Result { } fn main() { - let task = task::spawn(async { + let reader_task = task::spawn(async { let result = read_file("data.csv"); match result { Ok(s) => println!("{}", s), @@ -23,7 +23,7 @@ fn main() { } }); println!("Started task!"); - task::block_on(task); + task::block_on(reader_task); println!("Stopped task!"); } ``` From e47d4d6701e0fa01754fdd94edf718a3dba4d956 Mon Sep 17 00:00:00 2001 From: skorgu Date: Fri, 16 Aug 2019 16:45:37 -0400 Subject: [PATCH 4/6] Remove some doubled backticks. --- docs/src/overview/std-and-library-futures.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/src/overview/std-and-library-futures.md b/docs/src/overview/std-and-library-futures.md index 98cdfb4..0f50bce 100644 --- a/docs/src/overview/std-and-library-futures.md +++ b/docs/src/overview/std-and-library-futures.md @@ -6,11 +6,11 @@ Rust has two kinds of types commonly referred to as `Future`: - the first is `std::future::Future` from Rust’s [standard library](https://doc.rust-lang.org/std/future/trait.Future.html). - the second is `futures::future::Future` from the [futures-rs crate](https://docs.rs/futures-preview/0.3.0-alpha.17/futures/prelude/trait.Future.html), currently released as `futures-preview`. -The future defined in the [futures-rs](https://docs.rs/futures-preview/0.3.0-alpha.17/futures/prelude/trait.Future.html) crate was the original implementation of the type. To enable the `async/await` syntax, the core Future trait was moved into Rust’s standard library and became `std::future::Future`. In some sense, the `std``::future::Future` can be seen as a minimal subset of `futures::future::Future`. +The future defined in the [futures-rs](https://docs.rs/futures-preview/0.3.0-alpha.17/futures/prelude/trait.Future.html) crate was the original implementation of the type. To enable the `async/await` syntax, the core Future trait was moved into Rust’s standard library and became `std::future::Future`. In some sense, the `std::future::Future` can be seen as a minimal subset of `futures::future::Future`. It is critical to understand the difference between `std::future::Future` and `futures::future::Future`, and the approach that `async-std` takes towards them. In itself, `std::future::Future` is not something you want to interact with as a user—except by calling `.await` on it. The inner workings of `std::future::Future` are mostly of interest to people implementing `Future`. Make no mistake—this is very useful! Most of the functionality that used to be defined on `Future` itself has been moved to an extension trait called `[FuturesExt](https://docs.rs/futures-preview/0.3.0-alpha.17/futures/future/trait.FutureExt.html)`. From this information, you might be able to infer that the `futures` library serves as an extension to the core Rust async features. -In the same tradition as `futures`, `async-std` re-exports the core `std::future::``Future` type. You can get actively opt into the extensions provided by the `futures-preview` crate by adding it your `Cargo.toml` and importing `FuturesExt`. +In the same tradition as `futures`, `async-std` re-exports the core `std::future::Future` type. You can get actively opt into the extensions provided by the `futures-preview` crate by adding it your `Cargo.toml` and importing `FuturesExt`. ## Interfaces and Stability @@ -24,4 +24,4 @@ There’s some support functions that we see as important for working with futur ## Streams and Read/Write/Seek/BufRead traits -Due to limitations of the Rust compiler, those are currently implemented in `async_std`, but cannot be implemented by users themselves. \ No newline at end of file +Due to limitations of the Rust compiler, those are currently implemented in `async_std`, but cannot be implemented by users themselves. From 9e89e7911393bcaeea7314ffe52ce3b13476c565 Mon Sep 17 00:00:00 2001 From: skorgu Date: Fri, 16 Aug 2019 16:48:34 -0400 Subject: [PATCH 5/6] Remove errant backticks --- docs/src/tutorial/receiving_messages.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/tutorial/receiving_messages.md b/docs/src/tutorial/receiving_messages.md index a60fe9f..1c8552f 100644 --- a/docs/src/tutorial/receiving_messages.md +++ b/docs/src/tutorial/receiving_messages.md @@ -89,4 +89,4 @@ where } }) } -```s \ No newline at end of file +``` From 9d56089ed2f7c1d6ab574628210aa3f8bf3fc996 Mon Sep 17 00:00:00 2001 From: skorgu Date: Fri, 16 Aug 2019 16:55:37 -0400 Subject: [PATCH 6/6] Fix FuturesExt formatting --- docs/src/overview/std-and-library-futures.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/overview/std-and-library-futures.md b/docs/src/overview/std-and-library-futures.md index 98cdfb4..4c924a1 100644 --- a/docs/src/overview/std-and-library-futures.md +++ b/docs/src/overview/std-and-library-futures.md @@ -8,7 +8,7 @@ Rust has two kinds of types commonly referred to as `Future`: The future defined in the [futures-rs](https://docs.rs/futures-preview/0.3.0-alpha.17/futures/prelude/trait.Future.html) crate was the original implementation of the type. To enable the `async/await` syntax, the core Future trait was moved into Rust’s standard library and became `std::future::Future`. In some sense, the `std``::future::Future` can be seen as a minimal subset of `futures::future::Future`. -It is critical to understand the difference between `std::future::Future` and `futures::future::Future`, and the approach that `async-std` takes towards them. In itself, `std::future::Future` is not something you want to interact with as a user—except by calling `.await` on it. The inner workings of `std::future::Future` are mostly of interest to people implementing `Future`. Make no mistake—this is very useful! Most of the functionality that used to be defined on `Future` itself has been moved to an extension trait called `[FuturesExt](https://docs.rs/futures-preview/0.3.0-alpha.17/futures/future/trait.FutureExt.html)`. From this information, you might be able to infer that the `futures` library serves as an extension to the core Rust async features. +It is critical to understand the difference between `std::future::Future` and `futures::future::Future`, and the approach that `async-std` takes towards them. In itself, `std::future::Future` is not something you want to interact with as a user—except by calling `.await` on it. The inner workings of `std::future::Future` are mostly of interest to people implementing `Future`. Make no mistake—this is very useful! Most of the functionality that used to be defined on `Future` itself has been moved to an extension trait called [`FuturesExt`](https://docs.rs/futures-preview/0.3.0-alpha.17/futures/future/trait.FutureExt.html). From this information, you might be able to infer that the `futures` library serves as an extension to the core Rust async features. In the same tradition as `futures`, `async-std` re-exports the core `std::future::``Future` type. You can get actively opt into the extensions provided by the `futures-preview` crate by adding it your `Cargo.toml` and importing `FuturesExt`. @@ -24,4 +24,4 @@ There’s some support functions that we see as important for working with futur ## Streams and Read/Write/Seek/BufRead traits -Due to limitations of the Rust compiler, those are currently implemented in `async_std`, but cannot be implemented by users themselves. \ No newline at end of file +Due to limitations of the Rust compiler, those are currently implemented in `async_std`, but cannot be implemented by users themselves.