-
Notifications
You must be signed in to change notification settings - Fork 37
Bikeshedding: syntax of async iteration statement #11
Comments
Personally I agree that putting async first and staying consistent with async functions would be better. |
There's just something weird to me about Another option would be: async function af() {
for (await let x of y) {
// Stuff
}
} Or async function af() {
for await (let x of y) {
// Stuff
}
} |
The await keyword makes it seem like the for loop is going to return a promise that's being awaited, which might be a bit confusing. |
I think I'm going to go with Rationale:
Thanks @RangerMauve : ) |
@zenparsing Awesome, can't wait for this to take off! :D |
Just for completeness, what about something like for (await x of y) {
// Stuff
} under the assumption that |
I think that it'd be better to have only the minimal amount of differences from a regular for of loop. |
@benjamn that might give the impression that for (await let x of y) {
// Stuff
} |
@zenparsing for the record, Python 3.5 recently introduced async iterators and they went with |
@benjamingr Thanks for the link. In Dart it's "await for": https://www.dartlang.org/articles/beyond-async/ |
Am I right to imagine this loop (or any of the syntaxes that have been proposed) for await (let x of y) {
// Stuff
} would desugar to something like let iter$0 = y[Symbol.asyncIterator](), record$0;
while (!(record$0 = await iter$0.next()).done) {
let x = record$0.value;
// Stuff
} or am I missing some subtleties? |
If I'm right about that desugaring, then the most important thing about this new loop syntax seems to be that it invokes |
|
Yeah, that's true. I can also appreciate the argument that I guess I'm sold on |
I like
|
From the recent discussion I also support |
I personally like: await for (const x of asyncIterator) {
// do stuff...
} because in the case that |
@eggers That's true, but I don't really feel comfortable having to use lookahead to determine whether the "await" is a part of the "for", rather than the unary operator. |
Closing this one for now, although I'm sure the bikeshedding will come up again : ) |
The currently proposed syntax is:
I originally chose that because it sounds nice in a natural language kind of way.
Would it be better to have the async in front, for consistency with async functions?
Thinking ahead to a possible
do-async
, which would make more sense?Or
@domenic @bterlson Any opinions here?
The text was updated successfully, but these errors were encountered: