[swift-evolution] await keyword "scope"

Brent Royal-Gordon brent at architechies.com
Tue Sep 19 01:02:34 CDT 2017

> On Sep 18, 2017, at 9:47 AM, Adam Kemp <adam_kemp at apple.com> wrote:
>> Would it be possible to actually fix this? That is, make the code covered by the `await` evaluate synchronous subexpressions first, such that the code sample above is equivalent to this?
>> 	@IBAction func buttonDidClick(sender:AnyObject) {
>> 	    beginAsync {
>> 		let $temp1 = self.resizeSwitch.isOn
>> 		let $temp2 = await downloadImage()
>> 	        let image = await processImage($temp2, resize: $temp1)
>> 	        displayImage(image)
>> 	    }
>> 	}
> That violates the defined order of evaluation for function arguments.

I understand that, but this order of evaluation was designed before we had `await`. I'm suggesting that, now that we do, we should change the order so that synchronous subexpressions are evaluated before asynchronous ones.

> You could also write code in which the (async) first argument function call has side effects that alter the result of the second argument expression. I’m not saying that’s good code, but it’s possible, and the language defines the order of evaluation so that code like that will have a predictable behavior.

You could write something like that, but as you say, that's not necessarily good code. Honestly, I don't think you can write good code that depends on one part of an expression being evaluated after an async call in another part of the expression completes.

Brent Royal-Gordon

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170918/1afe7405/attachment.html>

More information about the swift-evolution mailing list