6 ms·
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
by apo 7y ago
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?
- thsowers 7y agoexpression.await
- nailer 7y agoCan you show us an example of, eg, an HTTP request?
- steveklabnik 7y agoHere is a small TCP client example: https://github.com/rustasync/runtime/blob/master/examples/tcp-client.rs 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.
- mrkurt 7y agoIt's basically just like a method call on a future: use hyper::Client; let client = Client::new(); let resp = client.get(url).await;
- chucksmash 7y agoPostfixed 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;
- svnpenn 7y agoawait goes inside the function, at least thats how its done with JavaScript - do you have evidence otherwise? https://developer.mozilla.org/Web/JavaScript/Reference/Operators/await https://developer.mozilla.org/Web/JavaScript/Reference/Opera...
- steveklabnik 7y agoI 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.
- k__ 7y agoThey worte explicitly that Rust went a different way than C#/JS
- steveklabnik 7y agoIt's true, but that's around let result = do_stuff().await; vs let result = await do_stuff(); not what your parent is talking about.
- k__ 7y agoAh, they meant like await goes into async functions etc.
- SamBam 7y agoI 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.
- deleted 7y ago[deleted]