[swift-evolution] [Concurrency] A slightly different perspective
Nathan Gray
n8gray at n8gray.org
Fri Sep 1 02:09:45 CDT 2017
> On Aug 31, 2017, at 3:31 PM, Marc Schlichte <marc.schlichte at googlemail.com> wrote:
>
>
>> 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.
It's true that actors would require a solution to the queue confusion problem, but not every program will want to use actors. My position is that the syntax of async/await demands a solution with or without actors. If we're ripping open the walls anyway let's fix the plumbing!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170901/c7b997fe/attachment.html>
More information about the swift-evolution
mailing list