Skip to content

[SE-0298: Async/Await: Sequences] Enable by default. #35954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ Swift Next
}
```

* [SE-0298][]:

The "for" loop can be used to traverse asynchronous sequences in asynchronous code:

```swift
for try await line in myFile.lines() {
// Do something with each line
}
```

Asynchronous for loops use asynchronous sequences, defined by the protocol
`AsyncSequence` and its corresponding `AsyncIterator`.

**Add new entries to the top of this section, not here!**

Swift 5.4
Expand Down Expand Up @@ -8309,6 +8322,7 @@ Swift 1.0
[SE-0286]: <https://github.com/apple/swift-evolution/blob/main/proposals/0286-forward-scan-trailing-closures.md>
[SE-0287]: <https://github.com/apple/swift-evolution/blob/main/proposals/0287-implicit-member-chains.md>
[SE-0296]: <https://github.com/apple/swift-evolution/blob/main/proposals/0296-async-await.md>
[SE-0298]: <https://github.com/apple/swift-evolution/blob/main/proposals/0298-asyncsequence.md>

[SR-75]: <https://bugs.swift.org/browse/SR-75>
[SR-106]: <https://bugs.swift.org/browse/SR-106>
Expand Down
6 changes: 2 additions & 4 deletions lib/Parse/ParseStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2127,11 +2127,9 @@ ParserResult<Stmt> Parser::parseStmtForEach(LabeledStmtInfo LabelInfo) {
SourceLoc AwaitLoc;
SourceLoc TryLoc;

if (shouldParseExperimentalConcurrency() &&
Tok.isContextualKeyword("await")) {
if (Tok.isContextualKeyword("await")) {
AwaitLoc = consumeToken();
} else if (shouldParseExperimentalConcurrency() &&
Tok.is(tok::kw_try)) {
} else if (Tok.is(tok::kw_try)) {
TryLoc = consumeToken();
if (Tok.isContextualKeyword("await")) {
AwaitLoc = consumeToken();
Expand Down
3 changes: 2 additions & 1 deletion test/Parse/foreach_async.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency
// RUN: %target-typecheck-verify-swift
// REQUIRES: concurrency
import _Concurrency

struct AsyncRange<Bound: Comparable & Strideable>: AsyncSequence, AsyncIteratorProtocol where Bound.Stride : SignedInteger {
var range: Range<Bound>.Iterator
Expand Down