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

async is huge, and I'm worried about future similar changes.

Suddenly "x.y" means member access.. except for x.await, which has a magic different meaning I still don't really understand. And adding 'await' to a function declaration magicly mangles it in various ways.



If you’re interested, I found this blog post [1] a really solid introduction to what async / await are in Rust, and how they’re used.

[1] https://os.phil-opp.com/async-await/


Honestly I haven't found those things to be problems at all. ".await" really isn't confusing. I think you meant "adding 'async'" to a function declaration --- it seems fine, but I personally don't use it.


The .await is another thing one needs to teach, and fairly early on so that people reading code examples don't get confused by where the "await" member of structures are. It just seems like a really bizarre break in what was fairly clean notation.


For me, it helps that ".await" appears as a keyword because of syntax highlighting. It is an odd syntax, but the alternative way of making await a prefix operator instead of a postfix operator would have been way worse for readability. Compare

  let bar = list_foos().await.first().list_bars().await.first();
vs.

  let bar = (await (await list_foos()).first().list_bars()).first();


You can always write `fn foo() -> impl Future` and mangle your code manually, using future combinators, though.


I do agree. The syntax they chose was not my favorite option. I wish they at least had put the stupid parentheses, so you can think of awaiting as an operation that the compiler "magically" puts on Futures in async contexts.

I know that's not technically right, but it still seems a better approximation to reality.




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

Search: