6 ms·
Wouldn'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
by blattimwind 7y ago
Wouldn'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 7y 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 7y 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 7y agoPython also chains methods. And having to write (await (await (await foo).bar()).baz()) is annoying.
- imtringued 7y 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 7y agoWhat happens if f.bar() throws an exception asynchronously?