[swift-evolution] [Concurrency] A slightly different perspective

Marc Schlichte marc.schlichte at googlemail.com
Thu Aug 31 17:31:32 CDT 2017


> Am 01.09.2017 um 00:04 schrieb Nathan Gray via swift-evolution <swift-evolution at swift.org>:
> 
> 1. Fixing "queue confusion" *must* be part of this proposal.  The key bit of "magic" offered by async/await over continuation passing is that you're working in a single scope.  A single scope should execute on a single queue unless the programmer explicitly requests otherwise.  Queue hopping is a surprising problem in a single scope, and one that there's currently no adequate solution for.
> 
> Also consider error handling.  In this code it's really hard to reason about what queue the catch block will execute on!  And what about the defer block?
> 
> ```
> startSpinner()
> defer { stopSpinner() }
> do {
>   try await doSomeWorkOnSomeQ()
>   try await doSomeMoreWorkOnSomeOtherQ()
> } catch {
>   // Where am I?
> }
> ```
> 
> Please, please, PLEASE don't force us to litter our business logic with gobs of explicit queue-hopping code!
> 

In my understanding, this is the advantage of using Actors, as calling `await` on actor functions is guaranteed to continue on the queue of the calling actor.

Only if you call „legacy“ non-actor async functions, you have to take care of queue hopping by yourself - as you do today.

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


More information about the swift-evolution mailing list