[swift-evolution] [Concurrency] Fixing race conditions in async/await example

Thorsten Seitz tseitz42 at icloud.com
Mon Sep 11 23:56:53 CDT 2017


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 }
}

-Thorsten


> Am 11.09.2017 um 22:49 schrieb Adam Kemp via swift-evolution <swift-evolution at swift.org>:
> 
> Sorry, I was away for a while so I couldn’t respond to this right away.
> 
>> On Aug 29, 2017, at 12:29 AM, Jonathan Hull <jhull at gbis.com> wrote:
>> 
>> If you are asking about how ‘async’ (which defers ‘await’) composes, it actually composes completely naturally… and I believe that should be provable.  
> 
> Can you show me specifically how that would work, then? For instance, let’s say that we want to start N (unknown, i.e., not constant) async requests and then, only once all of them have begun, wait for all them to complete. What would that code look like?
> 
> Extending that example, let’s say we wanted to use one function to start the N requests and then use a different function to wait on them. What would be the signatures of these functions?
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution


More information about the swift-evolution mailing list