[swift-evolution] [Concurrency] async/await + actors

Kenny Leung kenny_leung at pobox.com
Sat Sep 9 17:40:27 CDT 2017


Then isn’t the example functionally equivalent to:

    func doit() {
        DispatchQueue.global().async {
            let dataResource  = loadWebResource("dataprofile.txt")
            let imageResource = loadWebResource("imagedata.dat")
            let imageTmp      = decodeImage(dataResource, imageResource)
            let imageResult   = dewarpAndCleanupImage(imageTmp)
            DispatchQueue.main.async {
                self.imageResult = imageResult
            }
        }
    }

if all of the API were synchronous? Why wouldn’t we just exhort people to write synchronous API code and continue using libdispatch? What am I missing?

-Kenny


> On Sep 8, 2017, at 2:33 PM, David Hart <david at hartbit.com> wrote:
> 
> 
>> On 8 Sep 2017, at 20:34, Kenny Leung via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> Hi All.
>> 
>> A point of clarification in this example:
>> 
>> func loadWebResource(_ path: String) async -> Resource
>> func decodeImage(_ r1: Resource, _ r2: Resource) async -> Image
>> func dewarpAndCleanupImage(_ i : Image) async -> Image
>> 
>> func processImageData1() async -> Image {
>>     let dataResource  = await loadWebResource("dataprofile.txt")
>>     let imageResource = await loadWebResource("imagedata.dat")
>>     let imageTmp      = await decodeImage(dataResource, imageResource)
>>     let imageResult   = await dewarpAndCleanupImage(imageTmp)
>>     return imageResult
>> }
>> 
>> Do these:
>> 
>> await loadWebResource("dataprofile.txt")
>> await loadWebResource("imagedata.dat")
>> 
>> happen in in parallel?
> 
> They don’t happen in parallel.
> 
>> If so, how can I make the second one wait on the first one? If not, how can I make them go in parallel?
>> 
>> Thanks!
>> 
>> -Kenny
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 

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


More information about the swift-evolution mailing list