Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


I think it should be fairly clear that it's inside an async function, I mostly don't think that was part of the question, which was about syntax.

chucksmash was concisely showing the syntax for an async function and how you can call it with await.


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


It's true, but that's around

  let result = do_stuff().await;
vs

  let result = await do_stuff();
not what your parent is talking about.


Ah, they meant like await goes into async functions etc.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: