Live data from Hacker News

Update on await syntax in Rust

boats.gitlab.io

41–50 of 199 posts

Re: Update on await syntax in Rust

#41
post #36

The article doesn't actually show what the new syntax looks like. Nor does the article linked in the first paragraph. What's a simple example of the new syntax?

Postfixed and preceded by a dot is my understanding:

    pub async fn do_stuff() {
        // ...
    }

    // elsewhere, inside a fn
    // as svnpenn points out
    let result = do_stuff().await;

Re: Update on await syntax in Rust

#42
post #40

Earlier quoted context omitted.

expression.await

Can you show us an example of, eg, an HTTP request?

Here is a small TCP client example: https://github.com/rustasync/runtime/blob/master/examples/tc...

Note "async fn main" on line 15, and the ".await"s on 21 and 24.

Now, if you read my other comment about executors, this is using a crate called "runtime", which handles submitting it for you, see the `#[]` bit on line 14. Regardless, the syntax would look like this even without this crate; it just removes some boilerplate around the executor and submitting your future to it.

Re: Update on await syntax in Rust

#44
Awesome, thanks Rust team! I'm super excited for this to be stabilized.

> That won’t be the end of the async/await feature - there will be a lot of extensions left out of the minimum feature

Is there a summary of these somewhere for perusal?

Re: Update on await syntax in Rust

#45
post #36

The article doesn't actually show what the new syntax looks like. Nor does the article linked in the first paragraph. What's a simple example of the new syntax?

Postfixed and preceded by a dot is my understanding: pub async fn do_stuff() { // ... } // elsewhere, inside a fn // as svnpenn points out let result = do_stuff().await;

await goes inside the function, at least thats how its done with JavaScript - do you have evidence otherwise?

https://developer.mozilla.org/Web/JavaScript/Reference/Opera...

Re: Update on await syntax in Rust

#46
post #36

The article doesn't actually show what the new syntax looks like. Nor does the article linked in the first paragraph. What's a simple example of the new syntax?

Postfixed and preceded by a dot is my understanding: pub async fn do_stuff() { // ... } // elsewhere, inside a fn // as svnpenn points out let result = do_stuff().await;

[deleted]

Re: Update on await syntax in Rust

#47
post #45

Earlier quoted context omitted.

Postfixed and preceded by a dot is my understanding: pub async fn do_stuff() { // ... } // elsewhere, inside a fn // as svnpenn points out let result = do_stuff().await;

await goes inside the function, at least thats how its done with JavaScript - do you have evidence otherwise? https://developer.mozilla.org/Web/JavaScript/Reference/Opera...

I read your parent as suggesting that the line with `let` was made inside of another `async fn`. You're correct that you can only .await inside of one. You shouldn't be downvoted.

Re: Update on await syntax in Rust

#48

What a milestone! This was the most impressive work in open source decision-making that I have ever followed (in my limited experience). People have contributed thousands of comments discussing this for over a year. It has even caused the team to rethink how discussions like this should be guided in the future beyond comments on GitHub issues. I cannot imagine how difficult it has been to manage it all, and I applaud…

I hope time is spent better in the future: https://wiki.haskell.org/Wadler's_Law, https://en.m.wikipedia.org/wiki/Law_of_triviality

Re: Update on await syntax in Rust

#49
post #45

Earlier quoted context omitted.

Postfixed and preceded by a dot is my understanding: pub async fn do_stuff() { // ... } // elsewhere, inside a fn // as svnpenn points out let result = do_stuff().await;

await goes inside the function, at least thats how its done with JavaScript - do you have evidence otherwise? https://developer.mozilla.org/Web/JavaScript/Reference/Opera...

They worte explicitly that Rust went a different way than C#/JS

Re: Update on await syntax in Rust

#50
post #18

I'm nit going to stop using rust, but I find this very disappointing. One thing I strongly disagree with - - this article said other notations would require Rust users having to learn more notation. This still requires learning more notation, just it's easy to not even be aware it exists and think a struct had a member called await instead...

My understanding of the issue (which is shallow at best) is that it's a battle between a prefixing keyword or sigil which has the problem of causing the reader to scan back and forth in the statement when chaining multiple items, which sucks), or a postfixing keyword or sigil, with dot notation for a keyword to help parsing (and everyone seems to dislike the overloading of the dot notation for this). Ignoring sigils,…

> That said, I think a postfixing sigil would he been much better. It seems an important enough thing to denote that a bit of special syntax is called for

They can still introduce a sigil later, if the .await syntax turns out to be common enough in code that the long keyword hinders readability. This is how it was done with the try!(...) feature, which now uses ? as a sigil. But as the article points out, pure sigils are a scarce resource so .await might well be the best way to go anyway.

Post reply on HN