TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Async-await on stable Rust

1102 pointsby pietroalbiniover 5 years ago

32 comments

Dowwieover 5 years ago
This is a major milestone for Rust usability and developer productivity.<p>It was really hard to build asynchronous code until now. You had to clone objects used within futures. You had to chain asynchronous calls together. You had to bend over backwards to support conditional returns. Error messages weren&#x27;t very explanatory. You had limited access to documentation and tutorials to figure everything out. It was a process of walking over hot coals before becoming productive with asynchronous Rust.<p>Now, the story is different. Further a few heroes of the community are actively writing more educational materials to make it even easier for newcomers to become productive with async programming much faster than it took others.<p>Refactoring legacy asynchronous code to async-await syntax offers improved readability, maintainability, functionality, and performance. It&#x27;s totally worth the effort. Do your due diligence in advance, though, and ensure that your work is eligible for refactoring. Niko wasn&#x27;t kidding about this being a minimum viable product.
评论 #21474186 未加载
评论 #21482469 未加载
评论 #21474867 未加载
ComputerGuruover 5 years ago
I’ve been playing with async await in a polar opposite vertical than its typical use case (high tps web backends) and believe this was the missing piece to further unlock great ergonomic and productivity gains for system development: embedded no_std.<p>Async&#x2F;await lets you write non-blocking, single-threaded but highly interweaved firmware&#x2F;apps in allocation-free, single-threaded environments (bare-metal programming without an OS). The abstractions around stack snapshots allow seamless coroutines and I believe will make rust pretty much the easiest low-level platform to develop for.
评论 #21473880 未加载
评论 #21474029 未加载
评论 #21474305 未加载
评论 #21473798 未加载
评论 #21477330 未加载
评论 #21474700 未加载
评论 #21473986 未加载
评论 #21474274 未加载
评论 #21474923 未加载
fooycover 5 years ago
This is a big improvement, however this is still explicit&#x2F;userland asynchronous programming: If anything down the callstack is synchronous, it blocks everything. This requires every components of a program, including every dependency, to be specifically designed for this kind of concurency.<p>Async I&#x2F;O gives awesome performance, but further abstractions would make it easier and less risky to use. Designing everything around the fact that a program uses async I&#x2F;O, including things that have nothing to do with I&#x2F;O, is crazy.<p>Programming languages have the power to implement concurrency patterns that offer the same kind of performances, without the hassle.
评论 #21476661 未加载
评论 #21475125 未加载
评论 #21474891 未加载
评论 #21474618 未加载
评论 #21480784 未加载
评论 #21476707 未加载
评论 #21475042 未加载
评论 #21480748 未加载
评论 #21480240 未加载
评论 #21474804 未加载
评论 #21474907 未加载
评论 #21475610 未加载
评论 #21475514 未加载
评论 #21478108 未加载
评论 #21476300 未加载
评论 #21480136 未加载
GolDDranksover 5 years ago
This is big! Turns out that syntactic support for asynchronous programming in Rust isn&#x27;t just syntactic: it enables the compiler to reason about the lifetimes in asynchronous code in a way that wasn&#x27;t possible to implement in libraries. The end result of having async&#x2F;await syntax is that async code reads just like normal Rust, which definitely wasn&#x27;t the case before. This is a huge improvement in usability.
评论 #21473464 未加载
ralusekover 5 years ago
Isn&#x27;t it kind of a poor design choice that Rust will not actually begin execution of the function until `.await` is called? If I didn&#x27;t want to execute the function yet, I wouldn&#x27;t have invoked it. Awaiting is a completely different concept than invoking, why overload it?<p>If you want to defer execution of a promise until you await it, you can always do that, but this paradigm forces you to do that. The problem is then, how do I do parallel execution of asynchronous tasks?<p>In JavaScript I could do<p><pre><code> const results = await Promise.all([ asyncTaskA(), asyncTaskB(), asyncTaskC() ]); </code></pre> and those will execute simultaneously and await all results.<p>And that&#x27;s me deferring execution to the point that I&#x27;d like to await it, but in JavaScript you could additionally do<p><pre><code> const results = await Promise.all([ alreadyExecutingPromiseA, alreadyExecutingPromiseB, alreadyExecutingPromiseC ]); </code></pre> Where I pass in the actual promises which have returned from having called the functions at some point previously.<p>So how is parallel execution handled in Rust?
评论 #21474570 未加载
评论 #21473830 未加载
评论 #21473816 未加载
评论 #21474352 未加载
评论 #21473905 未加载
评论 #21473814 未加载
评论 #21473879 未加载
评论 #21477596 未加载
评论 #21473901 未加载
评论 #21497323 未加载
评论 #21473850 未加载
评论 #21475922 未加载
sudeepjover 5 years ago
This is going to open the flood gates. I am sure lot of people were just waiting for this moment for Rust adoption. I for one was definitely in this boat.<p>Also, this has all the goodness: open-source, high quality engineering, design in open, large contributors to a complex piece of software. Truly inspiring!
评论 #21473568 未加载
评论 #21473622 未加载
评论 #21473433 未加载
kodablahover 5 years ago
I&#x27;ve been working with alpha futures, tokio, hyper, etc with async&#x2F;await support on rust beta (didn&#x27;t use async std yet) and can attest to them working quite well. There was quite a learning curve for me to know when to use arc, mutex, different stream combinators, and understand raw polling, but after I did, writing the code became a bit easier. I suggest anyone wanting to learn to grab a tcp-level networking project&#x2F;idea&#x2F;protocol and grind on it for days, heh.
评论 #21474772 未加载
MuffinFlavoredover 5 years ago
For JavaScript developers expecting to jump over to Rust and be productive now that async&#x2F;await is stable:<p>I&#x27;m pretty sure the state of affairs for async programming is still a bit &quot;different&quot; in Rust land. Don&#x27;t you need to spawn async tasks into an executor, etc.?<p>Coming from JavaScript, the built in event-loop handles all of that. In Rust, the &quot;event loop&quot; so to speak is typically a third party library&#x2F;package, <i>not</i> something provided by the language&#x2F;standard itself.
评论 #21474645 未加载
pimeysover 5 years ago
The same day as async&#x2F;await hits stable, the next Prisma alpha is released and is the first alpha that&#x27;s based on Futures and async&#x2F;await.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;prisma&#x2F;prisma-engine&#x2F;" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;prisma&#x2F;prisma-engine&#x2F;</a><p>Been working with the ecosystem since the first version of futures some years ago, and I must say how things are right now it&#x27;s definitely much much easier.<p>There are still optimizations to be made, but IO starts to be in a good shape!
评论 #21477515 未加载
评论 #21477733 未加载
losvedirover 5 years ago
Exciting! I know this has been a long time coming, so congrats to everyone for finally landing it in stable.<p>As a rust noob, small question based on the example given: Why does `another_function` have to be defined with `async fn`? Naively, I would expect that because it calls `future.await` on its own async call, that from the &quot;outside&quot; it doesn&#x27;t seem like an async function at all. Or do you have to tag any function as async if it calls an async function, whether or not it returns a future?
评论 #21475368 未加载
评论 #21475100 未加载
评论 #21475017 未加载
lenkiteover 5 years ago
Does Rust offer <i>composable</i> futures ? Something like Javas CompletableFuture or Clojure&#x27;s <a href="https:&#x2F;&#x2F;github.com&#x2F;leonardoborges&#x2F;imminent" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;leonardoborges&#x2F;imminent</a> ?
评论 #21480629 未加载
pornelover 5 years ago
If you&#x27;re just starting to learn Rust, I suggest waiting a little before using async. It&#x27;s awesome, BUT libraries, tutorials, etc. will need a while to update from the prototype verion of Futures (AKA v0.1) to the final version (std::future). Changes made during standardization were relatively minor, but there&#x27;s no point learning two versions of Futures and dealing with temporary chaos while the ecosystem switches to the final one.
stubishover 5 years ago
This seems very similar to Python&#x27;s approach, which I&#x27;ve been finding poor to use.<p>I was wondering if a more pleasant approach would be to add a &#x27;defer&#x27; keyword to return a future from an async call, and have the default call be to await and return the result (setting up a default scheduler if necessary). Requiring the await keyword to be inserted in the majority of locations seems poor UX, as is requiring callsites to all be updated when you update your synchronous API to async.
cdbattagsover 5 years ago
This is massive and props to the team! I have a small prototype for interop between 0.1 and 0.3 futures which are also compatible with async&#x2F;await first order.<p>Excited for where this takes us! Can&#x27;t wait for tokio 2.0 now.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;cdbattags&#x2F;async-actix-web" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;cdbattags&#x2F;async-actix-web</a>
person_of_colorover 5 years ago
Can someone explain the benefit of this programming paradigm to other applications besides web servers&#x2F;IO bound tasks?
评论 #21482052 未加载
faitswulffover 5 years ago
Will the Rust Programming Language book be updated with async&#x2F;await?
评论 #21473841 未加载
overthemoonover 5 years ago
I have honestly never enjoyed learning a language more than I&#x27;ve been enjoying Rust, the docs and material are so thorough and clear. Very excited to tackle this topic.
sergiotapiaover 5 years ago
How does Rust compare to Nim? It seems Nim is as fast as C, static binaries, and ergonomic UX. Whereas Rust looks like C++ mixed with bath salts.
评论 #21477281 未加载
bruntover 5 years ago
Looks like someone needs to update <a href="https:&#x2F;&#x2F;areweasyncyet.rs&#x2F;" rel="nofollow">https:&#x2F;&#x2F;areweasyncyet.rs&#x2F;</a>
评论 #21473707 未加载
评论 #21474067 未加载
jdanceover 5 years ago
I have never used async&#x2F;await and cant really understand it. Is it like coroutines in lua? It seems very similar. But I guess its not limited to one thread like lua? Whats makes it better then threaded IO? Losing the overhead of threads?<p>I like coroutines but thats mostly because they are not threads, they only switch execution on yield, and that makes them easy to reason about :)
评论 #21478026 未加载
golergkaover 5 years ago
This is great news!<p>I tried out Rust for a typical server-side app over a year ago (JSON API and PostgreSQL backend), and the lack of async-await was the main reason I switched back to Typescript afterwards, even though Diesel is probably the best ORM I&#x27;ve ever worked with. Time to give it a try again.
tracker1over 5 years ago
This is awesome... been waiting on this... looking at a lot at rocket and yew (really new with rust), and had been waiting to see the async stuff shake out before continuing (been holding for a few months now), may take a bit of time over the weekend to start up again.
MrBraover 5 years ago
Can anybody share their thoughts on which key features &#x2F; libs are still missing in Rust?
评论 #21478416 未加载
评论 #21480210 未加载
C14Lover 5 years ago
An interesting presentation on the history of futures in Rust (from RustLatam 2019):<p><a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=skos4B5x7qE" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=skos4B5x7qE</a>
sbmthakurover 5 years ago
Rust beginner here who writes a lot of async code in Node.js. If I am to start writing async code in Rust, should I directly pick up async-await? Or should I first understand how it is done in the current way?
评论 #21482139 未加载
aashcanover 5 years ago
All we need are a few migration guides for Tokio, Hyper, Futures...
ldngover 5 years ago
I would be interested to know if a comparison between async and sync API at level exists. I have this intuitive but probably wrong feeling that async often implies memory overhead.
wiineethover 5 years ago
Is there anyone who has used rust instead of C++? What&#x27;s your opinion on it?
adgasfover 5 years ago
Can anyone help explain if Rust asyncs are hot (as in JavaScript, C++) or cold (as in F#)?
评论 #21475345 未加载
评论 #21475430 未加载
trpcover 5 years ago
Thank you Alex Crichton, Niko Matsakis and all other core devs, Rust is by far the most well designed programming language I&#x27;ve ever dealt with. It&#x27;s a masterpiece of software engineering IMO.
bullenover 5 years ago
How does rust perform in parallel on the same memory?<p>I heard it uses locks?<p>This is not on the same memory right? <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=21469295" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=21469295</a><p>If you want to do joint (on the same memory) parallel HTTP with Java I have a stable solution for you: <a href="https:&#x2F;&#x2F;github.com&#x2F;tinspin&#x2F;rupy" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tinspin&#x2F;rupy</a>
评论 #21473963 未加载
评论 #21473702 未加载
eeZah7Uxover 5 years ago
The level of fanboyism in the comments is saddening. Many other fast and productive languages have async since a while.
评论 #21477903 未加载
评论 #21477573 未加载
评论 #21475931 未加载
评论 #21505127 未加载