- Is the problem being addressed significant enough to warrant a change to Swift?
Yes
- Does this proposal fit well with the feel and direction of Swift?
I am uncertain on this:
I think that the variation of requiring try in an "async let" initializer would probably be beneficial, unless it would be confused as throwing immediately, and not when awaited.
The variation of requiring an "async let" to be explicitly awaited would also be beneficial, but may be incompatible with Swift's automatic choice of the deinitialization point.
As I said when "async let" was being discussed as part of structured-concurrency:
Syntactically I think it would be better to have async replace await directly in an "async let" statement instead of being lifted to be in front of the let .
This makes the requirement that async appear in an expression only where await can more obvious. The example given as:
func order() async -> Order { ... }
async let o1 = await order()
// should be written instead as
async let o2 = order()
Would instead be:
func order() async -> Order { ⌠}
let o1 = async await order()
// should be written instead as
let o2 = async order()
for which the first is more obviously wrong.
Similarly for the example of async on patterns:
func left() async -> String { "l" }
func right() async -> String { "r" }
async let (l, r) = (left(), right())
await l // at this point `r` is also assumed awaited-on
When the async is on the rhs, the fact that l and r will be awaited simultaneously is apparent.
func left() async -> String { "l" }
func right() async -> String { "r" }
let (l, r) = async (left(), right())
await l // at this point `r` is also assumed awaited-on
The only problems I see introduced with this syntax are the fact that the required error with async var is harder to justify:
async var x = nope() // error: 'async' can only be used with 'let' declarations
To:
var x = async nope() // error: 'async' can only be assigned to 'let' declarations
And the potential similarity of the syntax with that for a "futures" API.
However, I believe this is resolved by having "async let" values not be @escaping, as proposed.
- How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
A not-so-quick reading