[swift-evolution] [Concurrency] Fixing race conditions in async/await example
Thorsten Seitz
tseitz42 at icloud.com
Wed Sep 13 14:23:31 CDT 2017
> Am 12.09.2017 um 21:18 schrieb Adam Kemp <adam.kemp at apple.com>:
>
>> On Sep 11, 2017, at 9:56 PM, Thorsten Seitz <tseitz42 at icloud.com> wrote:
>>
>> My hope would be for something along these lines:
>>
>> func createDownloadTasks(for urls: [URL]) -> [async Data] {
>> return urls.map { url in async downloadResource(url) }
>> }
>> func await(all tasks: [async Data]) async -> [Data] {
>> return tasks.map { task in await task }
>> }
>
> So that’s basically a new type with a special syntax. What is the advantage to doing it that way versus just introducing a new protocol?
Just syntactic sugar (like `?` for Optionals) which happens to align with the async/await syntax. But you are right, the syntactic sugar should represent a type which can be represented in the language. Syntactic sugar probably only makes sense if it stands for a fixed concrete type (like Optional) which is probably a bad idea compared to C# where we can customize the concrete task type. It just has to have a GetAwaiter method.
So there is no need for such syntactic sugar and it even is a hindrance.
-Thorsten
More information about the swift-evolution
mailing list