Swift doesn't have async/await
| Originator: | dan.abramov | ||
| Number: | rdar://17172652 | Date Originated: | 06.05.14 |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | 6 |
| Classification: | Reproducible: |
Summary:
Getting asynchronous programming right is hands-down the hardest thing in developing modern apps today. C# simplified the hell out of this with async/await. JS is not too far behind with yield and coroutines already in Node v 0.11, and async/await coming in ES7. That Swift doesn't support this feature is a big disappointment to me, but I'm hoping it's planned.
See http://tirania.org/blog/archive/2013/Aug-15.html (Callbacks as our Generations' Go To Statement)
“Our intellectual powers are rather geared to master static relations and that our powers to visualize processes evolving in time are relatively poorly developed. For that reason we should do (as wise programmers aware of our limitations) our utmost to shorten the conceptual gap between the static program and the dynamic process, to make the correspondence between the program (spread out in text space) and the process (spread out in time) as trivial as possible.”
Dijkstra
Steps to Reproduce:
1. Try to write a decent app with async calls
Expected Results:
try {
Busy = true;
UpdateUIStatus ("Taking a picture");
var picker = new Xamarin.Media.MediaPicker ();
var mFile = await picker.TakePhotoAsync (new Xamarin.Media.StoreCameraMediaOptions ());
var tagsCtrl = new GetTagsUIViewController (mFile.GetStream ());
// Call new iOS await API
await PresentViewControllerAsync (tagsCtrl, true);
UpdateUIStatus ("Submitting picture to server");
await PostPicToServiceAsync (mFile.GetStream (), tagsCtrl.Tags);
UpdateUIStatus ("Success");
} catch (OperationCanceledException) {
UpdateUIStatus ("Canceled");
} finally {
Busy = false;
}
Actual Results:
https://o.twimg.com/1/proxy.jpg?t=FQQVBhhUaHR0cDovL2YuY2wubHkvaXRlbXMvMEcwaDFxMTUyZDFVMHEyMjBXMWgvSW1hZ2UlMjAyMDEzLjA4LjA4JTIwMTElM0E1MyUzQTI0JTIwUE0ucG5nFAQWABIA&s=QI9GeZLSgLIb5f5fHpX911kqiOAAqp-0XmZ0fbgSGUk
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Duplicate filed.
Of course, we can implement it ourselves
It turns out that we can implement this feature ourselves:
https://alastairs-place.net/blog/2014/06/12/async-in-swift/
It isn't perfect, and inside the compiler there would likely be more scope for optimisations (like not making extra stacks all the time), but hey…