Closed
Description
This is the tracking issue for RFC 2394 (rust-lang/rfcs#2394), which adds async and await syntax to the language.
I will be spearheading the implementation work of this RFC, but would appreciate mentorship as I have relatively little experience working in rustc.
TODO:
Unresolved questions:
- Final syntax for
await
.Resolution of RFC: add futures and task system to libcore rfcs#2418Double-checkTry
implementations to which we want to commit
Activity
rpjohnst commentedon May 8, 2018
The discussion here seems to have died down, so linking it here as part of the
await
syntax question: https://internals.rust-lang.org/t/explicit-future-construction-implicit-await/7344withoutboats commentedon May 9, 2018
Implementation is blocked on #50307.
Pzixel commentedon May 10, 2018
About syntax: I'd really like to have
await
as simple keyword. For example, let's look on a concern from the blog:I agree here, but braces are evil. I think it's easier to remember that
?
has lower precedence thanawait
and end with it:let foo = await future?
It's easier to read, it's easier to refactor. I do believe it's the better approach.
Allows to better understand an order in which operations are executed, but imo it's less readable.
I do believe that once you get that
await foo?
executesawait
first then you have no problems with it. It's probably lexically more tied, butawait
is on the left side and?
is on the right one. So it's still logical enough toawait
first and handleResult
after it.If any disagreement exist, please express them so we can discuss. I don't understanda what's silent downvote stands for. We all wish good to the Rust.
alexreg commentedon May 10, 2018
I have mixed views on
await
being a keyword, @Pzixel. While it certainly has an aesthetic appeal, and is perhaps more consistent, givenasync
is a keyword, "keyword bloat" in any language is a real concern. That said, does havingasync
withoutawait
even make any sense, feature wise? If it does, perhaps we can leave it as is. If not, I'd lean towards makingawait
a keyword.Nemo157 commentedon May 10, 2018
It might be possible to learn that and internalise it, but there's a strong intuition that things that are touching are more tightly bound than things that are separated by whitespace, so I think it would always read wrong on first glance in practice.
It also doesn't help in all cases, e.g. a function that returns a
Result<impl Future, _>
:rpjohnst commentedon May 10, 2018
The concern here is not simply "can you understand the precedence of a single await+
?
," but also "what does it look like to chain several awaits." So even if we just picked a precedence, we would still have the problem ofawait (await (await first()?).second()?).third()?
.A summary of the options for
await
syntax, some from the RFC and the rest from the RFC thread:await { future }?
orawait(future)?
(this is noisy).await future?
or(await future)?
does what is expected (both of these feel surprising).await? future
(this is unusual).await
postfix somehow, as infuture await?
orfuture.await?
(this is unprecedented).?
did, as infuture@?
(this is "line noise").@alexreg It does. Kotlin works this way, for example. This is the "implicit await" option.
alexreg commentedon May 10, 2018
@rpjohnst Interesting. Well, I'm generally for leaving
async
andawait
as explicit features of the language, since I think that's more in the spirit of Rust, but then I'm no expert on asynchronous programming...Pzixel commentedon May 10, 2018
@alexreg async/await is really nice feature, as I work with it on day-to-day basis in C# (which is my primary language). @rpjohnst classified all possibilities very well. I prefer the second option, I agree on others considerations (noisy/unusual/...). I have been working with async/await code for last 5 years or something, it's really important to have such a flag keywords.
@rpjohnst
In my practice you never write two
await
's in one line. In very rare cases when you need it you simply rewrite it asthen
and don't use await at all. You can see yourself that it's much harder to read thanSo I think it's ok if language discourages to write code in such manner in order to make the primary case simpler and better.
hero awayfuture await?
looks interesting although unfamiliar, but I don't see any logical counterarguments against that.356 remaining items