From 6ee3bc31b4a570baba4644f274f4583acefa72f2 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 27 Sep 2019 12:40:10 -0400 Subject: [PATCH 01/12] Add "async-await hits beta" blog post --- posts/2019-09-27-Async-await-hits-beta.md | 160 ++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 posts/2019-09-27-Async-await-hits-beta.md diff --git a/posts/2019-09-27-Async-await-hits-beta.md b/posts/2019-09-27-Async-await-hits-beta.md new file mode 100644 index 000000000..d90ddd6c2 --- /dev/null +++ b/posts/2019-09-27-Async-await-hits-beta.md @@ -0,0 +1,160 @@ +--- +layout: post +title: "Async-await hits beta!" +author: Niko Matsakis +--- + +Big news! As of this writing, **syntactic support for async-await is +available in the Rust beta channel!** It will be available in the 1.39 +release, which is expected to be released on **November 7th, 2019**. +Once async-await hits stable, that will mark the culmination of a +**multi-year effort to enable efficient and ergonomic asynchronous I/O +in Rust**. It will not, however, mark the end of the road: there is +still more work to do, both in terms of polish (some of the error +messages we get today are, um, [not great]) and in terms of feature +set ([async fn in traits], anyone?). + +[not great]: https://github.com/rust-lang/rust/issues/64130 +[async fn in traits]: https://github.com/dtolnay/async-trait + +(If you're not familiar with what async-await is, don't despair! +There's a primer and other details later on in this post!) + +### Async-await support in the ecosystem growing rapidly + +But async-await has never been the entire story. To make good use of +async-await, you also need strong libraries and a vibrant ecosystem. +**Fortunately, you've got a lot of good choices, and they keep getting +better:** + +- the async runtime [tokio], for example, recently announced an [alpha + release][] that supports async-await; +- the [recently announced][] [async-std][] library was built from the + start on the new async-await syntax; +- using [wasm-bindgen-futures], you can even bridge Rust Futures with + [JavaScript promises]; +- finally, in addition to the core runtimes just mentioned, + async-await support is starting to become available in higher-level + [web frameworks][wf] as well. + +[wasm-bindgen-futures]: https://docs.rs/crate/wasm-bindgen-futures/0.2.16 +[tokio]: https://actix.rs/ +[actix]: https://actix.rs/ +[alpha release]: https://tokio.rs/blog/2019-08-alphas/ +[adding support]: https://github.com/actix/actix-web/issues/955#issuecomment-523266936 +[async-std]: https://async.rs/ +[recently announced]: https://async.rs/blog/announcing-async-std/ +[wf]: https://www.arewewebyet.org/topics/frameworks/ +[JavaScript promises]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises + +### Restructuring Async I/O in the Rust org + +Now that async-await is stable, we are taking the opportunity to make +some changes to our Rust team structure. The current structure +includes two working groups: the [Async Foundations WG], focused on +building up core language support, and the [Async Ecosystem WG], +focused on supporting the ecosystem develop. + +**In light of all the activity going on in the ecosystem, however, +there it not as much need for the [Async Ecosystem WG], and as such +we've decided to spin it down.** We'll be deprecating the [rustasync +github org]. The [areweasyncyet.rs] and [arewewebyet.org] websites +will move to the main [rust-lang org], but the fate of the other +projects will be decided by the people who built them. A few will +likely be deprecated, and the remainder will be moving out to be +maintained independently. + +[areweasyncyet.rs]: https://areweasyncyet.rs/ +[arewewebyet.org]: https://www.arewewebyet.org/ +[rustasync github org]: https://github.com/rustasync/ +[rust-lang org]: https://github.com/rust-lang/ +[Async Foundations WG]: https://rust-lang.github.io/compiler-team/working-groups/async-await/ +[Async Ecosystem WG]: https://github.com/rustasync/team +[Async Book]: https://github.com/rust-lang/async-book + +**The [Async Foundations WG], meanwhile, will continue, but with a +shift in focus.** Now that async-await is en route to stabilization, +the focus will be on polish, such as improving diagnostics, fixing +smaller bugs, and improving documentation such as the [Async +Book]. Once progress is made on that, we'll be considering what +features to implement next. + +### Async await: a quick primer + +So, what is async await? Async-await is a way to write functions that +can "pause", return control to the runtime, and then pick up from +where they left off. Typically those pauses are to wait for I/O, but +there can be any number of uses. + +You may be familiar with the async-await from other languages, such as +JavaScript or C#. Rust's version of the feature is similar, but with a +few key differences. + +To use async-await, you start by writing `async fn` instead of `fn`: + +```rust +async fn first_function() -> u32 { .. } +``` + +Unlike a regular function, calling an `async fn` doesn't do anything +to start -- instead, it returns a `Future`. This is a suspended +computation that is waiting to be executed. To actually *execute* +the future, you have to use the `.await` operator: + +```rust +async fn another_function() { + // Create the future: + let future = first_function(); + + // Await the future, which will execute it (and suspend + // this function if we encounter a need to wait for I/O): + let result: u32 = future.await; + ... +} +``` + +This example shows the first difference between Rust and other +languages: we write `future.await` instead of `await future`. This +syntax integrates better with Rust's `?` operator for propagating +errors (which, after all, are very common in I/O). One can simply +write `future.await?` to await the result of a future and propagate +errors. It also has the advantage of making method chaining painless. + +### Zero-cost futures + +The other difference between Rust futures and futures in other +languages is that they are based on a "poll" model, which makes them +**zero cost**. In other languages, invoking an async function +immediately creates a future and schedules it for execution: awaiting +the future isn't really necessary for it to execute. But this implies +some overhead for each future that is created. + +In contrast, in Rust, calling an async function does not do any +scheduling in and of itself, which means that we can compose a complex +nest of futures without incurring a "per-future cost". As an end-user, +though, the main thing you'll notice is that **futures feel "lazy"**: +they don't do anything until you await them. + +If you'd like a closer look at how futures work under the hood, +[withoutboats] gave a [great introduction in this talk][video] from +[Rust LATAM 2019]. + +[video]: https://www.youtube.com/watch?v=skos4B5x7qE +[Rust LATAM 2019]: https://rustlatam.org/ +[withoutboats]: https://rustlatam.org/ + +### Summary + +In summary, if you've an interest in using Async I/O in Rust, this is +a very exciting time! With async-await syntax hitting stable in +November, it's going to be easier than ever to write futures (in +particular, if you tried using the combinator-based futures in the +past, you'll find [async-await integrates much better with Rust's +borrowing system][bc]). Moreover, there are a now a number of great +runtimes and other libraries available in the ecosystem to work with. +So get out there and build stuff! + +(Oh, yeah, and please file bugs when you hit confusing or surprising +problems, so we can improve the user experience!) + +[bc]: http://aturon.github.io/tech/2018/04/24/async-borrowing/ From 14dd33f43dd785499b23a8925df5fbb63433a0cf Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 27 Sep 2019 13:39:42 -0400 Subject: [PATCH 02/12] add mention of rust-lang/wg-governance#25 --- posts/2019-09-27-Async-await-hits-beta.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/posts/2019-09-27-Async-await-hits-beta.md b/posts/2019-09-27-Async-await-hits-beta.md index d90ddd6c2..0b57f5069 100644 --- a/posts/2019-09-27-Async-await-hits-beta.md +++ b/posts/2019-09-27-Async-await-hits-beta.md @@ -79,6 +79,14 @@ smaller bugs, and improving documentation such as the [Async Book]. Once progress is made on that, we'll be considering what features to implement next. +(An aside: this is the first time that we've ever opted to spin *down* +a working group before, and we realized that we don't have a formal +policy for that. We've [created an issue][gov25] with the [governance +working group][gov-wg] to look into that for the future.) + +[gov25]: https://github.com/rust-lang/wg-governance/issues/25 +[gov-wg]: https://github.com/rust-lang/wg-governance/ + ### Async await: a quick primer So, what is async await? Async-await is a way to write functions that From 123e19b920ce000616f776335277a67471e4312e Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 27 Sep 2019 13:40:20 -0400 Subject: [PATCH 03/12] remove quotes --- posts/2019-09-27-Async-await-hits-beta.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2019-09-27-Async-await-hits-beta.md b/posts/2019-09-27-Async-await-hits-beta.md index 0b57f5069..f1d266b63 100644 --- a/posts/2019-09-27-Async-await-hits-beta.md +++ b/posts/2019-09-27-Async-await-hits-beta.md @@ -139,7 +139,7 @@ some overhead for each future that is created. In contrast, in Rust, calling an async function does not do any scheduling in and of itself, which means that we can compose a complex -nest of futures without incurring a "per-future cost". As an end-user, +nest of futures without incurring a per-future cost. As an end-user, though, the main thing you'll notice is that **futures feel "lazy"**: they don't do anything until you await them. From 5d91dd7d167529ed38b3f4eda30cdd7291b901e8 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 27 Sep 2019 13:41:43 -0400 Subject: [PATCH 04/12] cite book --- posts/2019-09-27-Async-await-hits-beta.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/posts/2019-09-27-Async-await-hits-beta.md b/posts/2019-09-27-Async-await-hits-beta.md index f1d266b63..2b6d79e5f 100644 --- a/posts/2019-09-27-Async-await-hits-beta.md +++ b/posts/2019-09-27-Async-await-hits-beta.md @@ -70,13 +70,13 @@ maintained independently. [rust-lang org]: https://github.com/rust-lang/ [Async Foundations WG]: https://rust-lang.github.io/compiler-team/working-groups/async-await/ [Async Ecosystem WG]: https://github.com/rustasync/team -[Async Book]: https://github.com/rust-lang/async-book +[async book]: https://github.com/rust-lang/async-book **The [Async Foundations WG], meanwhile, will continue, but with a shift in focus.** Now that async-await is en route to stabilization, the focus will be on polish, such as improving diagnostics, fixing -smaller bugs, and improving documentation such as the [Async -Book]. Once progress is made on that, we'll be considering what +smaller bugs, and improving documentation such as the [async +book]. Once progress is made on that, we'll be considering what features to implement next. (An aside: this is the first time that we've ever opted to spin *down* @@ -143,10 +143,12 @@ nest of futures without incurring a per-future cost. As an end-user, though, the main thing you'll notice is that **futures feel "lazy"**: they don't do anything until you await them. -If you'd like a closer look at how futures work under the hood, -[withoutboats] gave a [great introduction in this talk][video] from -[Rust LATAM 2019]. +If you'd like a closer look at how futures work under the hood, take a +look at [the executor section] of the [async book], or watch the +[excellent talk][video] that [withoutboats] gave at [Rust LATAM 2019] +on the topic. +[the executor section]: https://rust-lang.github.io/async-book/02_execution/04_executor.html [video]: https://www.youtube.com/watch?v=skos4B5x7qE [Rust LATAM 2019]: https://rustlatam.org/ [withoutboats]: https://rustlatam.org/ From 3e4ba1803caee22b3476d1547f5a27f4b650e025 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 27 Sep 2019 13:48:17 -0400 Subject: [PATCH 05/12] cite hyper --- posts/2019-09-27-Async-await-hits-beta.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/posts/2019-09-27-Async-await-hits-beta.md b/posts/2019-09-27-Async-await-hits-beta.md index 2b6d79e5f..3db7df32c 100644 --- a/posts/2019-09-27-Async-await-hits-beta.md +++ b/posts/2019-09-27-Async-await-hits-beta.md @@ -33,6 +33,7 @@ better:** start on the new async-await syntax; - using [wasm-bindgen-futures], you can even bridge Rust Futures with [JavaScript promises]; +- the [hyper library][hyper] has [migrated][hyper#1805] to adopt standard Rust futures; - finally, in addition to the core runtimes just mentioned, async-await support is starting to become available in higher-level [web frameworks][wf] as well. @@ -46,6 +47,8 @@ better:** [recently announced]: https://async.rs/blog/announcing-async-std/ [wf]: https://www.arewewebyet.org/topics/frameworks/ [JavaScript promises]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises +[hyper]: https://github.com/hyperium/hyper/ +[hyper#1805]: https://github.com/hyperium/hyper/issues/1805 ### Restructuring Async I/O in the Rust org From 94ec6390d4d53d11afbe90399d755248e78242ed Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 27 Sep 2019 13:49:49 -0400 Subject: [PATCH 06/12] cite hyper.rs, not gh project --- posts/2019-09-27-Async-await-hits-beta.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2019-09-27-Async-await-hits-beta.md b/posts/2019-09-27-Async-await-hits-beta.md index 3db7df32c..21d603d12 100644 --- a/posts/2019-09-27-Async-await-hits-beta.md +++ b/posts/2019-09-27-Async-await-hits-beta.md @@ -47,7 +47,7 @@ better:** [recently announced]: https://async.rs/blog/announcing-async-std/ [wf]: https://www.arewewebyet.org/topics/frameworks/ [JavaScript promises]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises -[hyper]: https://github.com/hyperium/hyper/ +[hyper]: https://hyper.rs [hyper#1805]: https://github.com/hyperium/hyper/issues/1805 ### Restructuring Async I/O in the Rust org From 59b31b1811664f4dd707de3fee55ef5f3f10cc6f Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 30 Sep 2019 13:14:20 -0400 Subject: [PATCH 07/12] apply nits from carl --- posts/2019-09-27-Async-await-hits-beta.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/posts/2019-09-27-Async-await-hits-beta.md b/posts/2019-09-27-Async-await-hits-beta.md index 21d603d12..170ed9ae8 100644 --- a/posts/2019-09-27-Async-await-hits-beta.md +++ b/posts/2019-09-27-Async-await-hits-beta.md @@ -28,7 +28,7 @@ async-await, you also need strong libraries and a vibrant ecosystem. better:** - the async runtime [tokio], for example, recently announced an [alpha - release][] that supports async-await; + release][] based on async-await; - the [recently announced][] [async-std][] library was built from the start on the new async-await syntax; - using [wasm-bindgen-futures], you can even bridge Rust Futures with @@ -39,7 +39,7 @@ better:** [web frameworks][wf] as well. [wasm-bindgen-futures]: https://docs.rs/crate/wasm-bindgen-futures/0.2.16 -[tokio]: https://actix.rs/ +[tokio]: https://tokio.rs/ [actix]: https://actix.rs/ [alpha release]: https://tokio.rs/blog/2019-08-alphas/ [adding support]: https://github.com/actix/actix-web/issues/955#issuecomment-523266936 From d1302bdca0a7e729161d9d9c87743e5acbacd7f3 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 30 Sep 2019 13:14:28 -0400 Subject: [PATCH 08/12] use stable to mean "on stable channel" only --- posts/2019-09-27-Async-await-hits-beta.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/posts/2019-09-27-Async-await-hits-beta.md b/posts/2019-09-27-Async-await-hits-beta.md index 170ed9ae8..a31ab4d20 100644 --- a/posts/2019-09-27-Async-await-hits-beta.md +++ b/posts/2019-09-27-Async-await-hits-beta.md @@ -52,11 +52,11 @@ better:** ### Restructuring Async I/O in the Rust org -Now that async-await is stable, we are taking the opportunity to make -some changes to our Rust team structure. The current structure -includes two working groups: the [Async Foundations WG], focused on -building up core language support, and the [Async Ecosystem WG], -focused on supporting the ecosystem develop. +Now that async-await is approaching stable, we are taking the +opportunity to make some changes to our Rust team structure. The +current structure includes two working groups: the [Async Foundations +WG], focused on building up core language support, and the [Async +Ecosystem WG], focused on supporting the ecosystem develop. **In light of all the activity going on in the ecosystem, however, there it not as much need for the [Async Ecosystem WG], and as such From 5138fdc364e4a5d474a580882e7f01c7aa91e65c Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 30 Sep 2019 13:14:43 -0400 Subject: [PATCH 09/12] remove outdated word --- posts/2019-09-27-Async-await-hits-beta.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/posts/2019-09-27-Async-await-hits-beta.md b/posts/2019-09-27-Async-await-hits-beta.md index a31ab4d20..ddac3c109 100644 --- a/posts/2019-09-27-Async-await-hits-beta.md +++ b/posts/2019-09-27-Async-await-hits-beta.md @@ -83,9 +83,9 @@ book]. Once progress is made on that, we'll be considering what features to implement next. (An aside: this is the first time that we've ever opted to spin *down* -a working group before, and we realized that we don't have a formal -policy for that. We've [created an issue][gov25] with the [governance -working group][gov-wg] to look into that for the future.) +a working group, and we realized that we don't have a formal policy +for that. We've [created an issue][gov25] with the [governance working +group][gov-wg] to look into that for the future.) [gov25]: https://github.com/rust-lang/wg-governance/issues/25 [gov-wg]: https://github.com/rust-lang/wg-governance/ From 2173ab9b2ceb057a030b40a67a7ffc674c166984 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 30 Sep 2019 15:45:21 -0400 Subject: [PATCH 10/12] fix futures utility crate --- posts/2019-09-27-Async-await-hits-beta.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/posts/2019-09-27-Async-await-hits-beta.md b/posts/2019-09-27-Async-await-hits-beta.md index ddac3c109..5f2ed834a 100644 --- a/posts/2019-09-27-Async-await-hits-beta.md +++ b/posts/2019-09-27-Async-await-hits-beta.md @@ -34,10 +34,14 @@ better:** - using [wasm-bindgen-futures], you can even bridge Rust Futures with [JavaScript promises]; - the [hyper library][hyper] has [migrated][hyper#1805] to adopt standard Rust futures; -- finally, in addition to the core runtimes just mentioned, - async-await support is starting to become available in higher-level +- the 0.3.0 version of the [futures-rs library][futures] will support + async-await and will be released by the time async-await hits stable + (you can use the [0.3.0-alpha][] releases now); +- finally, async-await support is starting to become available in higher-level [web frameworks][wf] as well. +[futures]: https://crates.io/crates/futures-preview +[0.3.0-alpha]: https://rust-lang-nursery.github.io/futures-rs/blog/2018/07/19/futures-0.3.0-alpha.1.html [wasm-bindgen-futures]: https://docs.rs/crate/wasm-bindgen-futures/0.2.16 [tokio]: https://tokio.rs/ [actix]: https://actix.rs/ From 068eea6bbe791b6ae9e74d668a3906140b6ed29e Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 30 Sep 2019 15:56:15 -0400 Subject: [PATCH 11/12] correct withoutboats URL --- posts/2019-09-27-Async-await-hits-beta.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2019-09-27-Async-await-hits-beta.md b/posts/2019-09-27-Async-await-hits-beta.md index 5f2ed834a..bd8bd3a5a 100644 --- a/posts/2019-09-27-Async-await-hits-beta.md +++ b/posts/2019-09-27-Async-await-hits-beta.md @@ -158,7 +158,7 @@ on the topic. [the executor section]: https://rust-lang.github.io/async-book/02_execution/04_executor.html [video]: https://www.youtube.com/watch?v=skos4B5x7qE [Rust LATAM 2019]: https://rustlatam.org/ -[withoutboats]: https://rustlatam.org/ +[withoutboats]: https://github.com/withoutboats ### Summary From e273341ddd729ea3ef1b8df453ce245471033ad3 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 30 Sep 2019 16:03:28 -0400 Subject: [PATCH 12/12] it is no longer sep 27 --- ...ync-await-hits-beta.md => 2019-09-30-Async-await-hits-beta.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename posts/{2019-09-27-Async-await-hits-beta.md => 2019-09-30-Async-await-hits-beta.md} (100%) diff --git a/posts/2019-09-27-Async-await-hits-beta.md b/posts/2019-09-30-Async-await-hits-beta.md similarity index 100% rename from posts/2019-09-27-Async-await-hits-beta.md rename to posts/2019-09-30-Async-await-hits-beta.md