4 ms·
Super excited to see async/await finally get close to MVP and landing. I am not a huge fan of ".await", but there isn't much more to be said -- my personal pref
by cyphar 8y ago
Super excited to see async/await finally get close to MVP and landing. I am not a huge fan of ".await", but there isn't much more to be said -- my personal preference of "#await" or "@await" does look like line-noise and I think there's no perfect answer to this one (await{} was too messy and no better than prefix-await, and (await foo))? had too many brackets).
I also appreciate that this proposal was insanely bike-shedded and so really, any decision is better than no decision. I would've been happy with "await << f()" if it meant we could get this feature (lots of Rust projects I'm interested in are waiting on async/await before focusing on further development).
- blattimwind 8y agoWouldn't "await expr" or "await@expr" (if you hate whitespace) make more sense compared to "expr await"? let db_conn = await pool.connect() (Which is what e.g. Python uses, with the downside that you tend to need to parenthize more because await has very low precedence). vs let db_conn = pool.connect() await .await is not soo bad, kinda method-y let db_conn = pool.connect().await
- eslaught 8y agoDid you see the previous post on this topic? They discussed this extensively: https://paper.dropbox.com/doc/Await-Syntax-Write-Up--AcIbhZ1tPTCloXb2fmFpBTt~Ag-t9NlOSeI4RQ8AINsaSSyJ https://paper.dropbox.com/doc/Await-Syntax-Write-Up--AcIbhZ1...
- cyphar 8y agoI don't think "expr await" would be a good choice but that isn't the decision that was made, and I wasn't arguing for it in the first place. TFA says that using alternative punctuation was decided against because it would lead to line-noise and I don't think there's much more to discuss -- I understand that position and respect it. My main issue with .await is that it does look method-y rather than keyword-y. But while I like Python's "await expr" syntax in Python the existence of ? and chaining of methods in Rust justifies having a different syntax for it.
- int_19h 8y agoPython also chains methods. And having to write (await (await (await foo).bar()).baz()) is annoying.
- imtringued 8y agoThat doesn't look like well written async code at all... You're not supposed to use await literally everywhere and especially not multiple times in a single line. Javascript already has an answer to this (Hint it was inspired by Monads but it isn't one): await foo.then(f => f.bar()).then(b => b.baz())
- int_19h 8y agoWhat happens if f.bar() throws an exception asynchronously?
- McWobbleston 8y ago@await does look like line noise, but if they're considering giving other constructs a postfix syntax, I think the noise is justified. Overloading the dot operator creates confusion, it gives the impression that .await is somehow related to data access instead of control flow