Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename async for to for await
  • Loading branch information
MajorBreakfast committed Apr 24, 2018
commit 15c2de48bb5efc4c49f5d32ac8ebd9a2c4fa13b7
6 changes: 3 additions & 3 deletions text/0000-async_await.md
Original file line number Diff line number Diff line change
Expand Up @@ -571,14 +571,14 @@ There are a couple of possible solutions:
This is left as an unresolved question to find another solution or decide which
of these is least bad.

## `async for` and processing streams
## `for await` and processing streams

Another extension left out of the RFC for now is the ability to process streams
using a for loop. One could imagine a construct like `async for`, which takes
using a for loop. One could imagine a construct like `for await`, which takes
an `IntoStream` instead of an `IntoIterator`:

```rust
async for value in stream {
for await value in stream {
println!("{}", value);
}
Copy link
Contributor

@MajorBreakfast MajorBreakfast Apr 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaScript is using the await keyword here which is IMO a better choice because async for loops await values.

It looks like this:

for await (const line of readLines(filePath)) {
  console.log(line);
}

Source: tc39 proposal for asynchronous iteration (Status: stage 4 (finished), shipping in Firefox and Chrome)

```
Expand Down