Skip to content

Commit 71617ba

Browse files
authored
Merge pull request #37254 from kavon/changelog-se310
2 parents 2cfca66 + 84632da commit 71617ba

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

CHANGELOG.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,50 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
66
Swift 5.5
77
---------
88

9+
* [SE-0310][]:
10+
11+
Read-only computed properties and subscripts can now define their `get` accessor to be `async` and/or `throws`, by writing one or both of those keywords between the `get` and `{`. Thus, these members can now make asynchronous calls or throw errors in the process of producing a value:
12+
```swift
13+
class BankAccount: FinancialAccount {
14+
var manager: AccountManager?
15+
16+
var lastTransaction: Transaction {
17+
get async throws {
18+
guard manager != nil else { throw BankError.notInYourFavor }
19+
return await manager!.getLastTransaction()
20+
}
21+
}
22+
23+
subscript(_ day: Date) -> [Transaction] {
24+
get async {
25+
return await manager?.getTransactions(onDay: day) ?? []
26+
}
27+
}
28+
}
29+
30+
protocol FinancialAccount {
31+
associatedtype T
32+
var lastTransaction: T { get async throws }
33+
subscript(_ day: Date) -> [T] { get async }
34+
}
35+
```
36+
Accesses to such members, like `lastTransaction` above, will require appropriate marking with `await` and/or `try`:
37+
```swift
38+
extension BankAccount {
39+
func meetsTransactionLimit(_ limit: Amount) async -> Bool {
40+
return try! await self.lastTransaction.amount < limit
41+
// ^~~~~~~~~~~~~~~~ this access is async & throws
42+
}
43+
}
44+
45+
46+
func hadWithdrawlOn(_ day: Date, from acct: BankAccount) async -> Bool {
47+
return await !acct[day].allSatisfy { $0.amount >= Amount.zero }
48+
// ^~~~~~~~~ this access is async
49+
}
50+
```
51+
52+
953
* [SE-0306][]:
1054

1155
Swift 5.5 includes support for actors, a new kind of type that isolates its instance data to protect it from concurrent access. Accesses to an actor's instance declarations from outside the must be asynchronous:
@@ -8433,6 +8477,7 @@ Swift 1.0
84338477
[SE-0298]: <https://github.com/apple/swift-evolution/blob/main/proposals/0298-asyncsequence.md>
84348478
[SE-0299]: <https://github.com/apple/swift-evolution/blob/main/proposals/0299-extend-generic-static-member-lookup.md>
84358479
[SE-0306]: <https://github.com/apple/swift-evolution/blob/main/proposals/0306-actors.md>
8480+
[SE-0310]: <https://github.com/apple/swift-evolution/blob/main/proposals/0310-effectful-readonly-properties.md>
84368481

84378482
[SR-75]: <https://bugs.swift.org/browse/SR-75>
84388483
[SR-106]: <https://bugs.swift.org/browse/SR-106>

0 commit comments

Comments
 (0)