[swift-evolution] [Concurrency] async/await + actors
marc.schlichte at googlemail.com
Fri Aug 25 02:04:37 CDT 2017
> Am 24.08.2017 um 22:05 schrieb Thomas via swift-evolution <swift-evolution at swift.org>:
>> Yes, I think it is mandatory that we continue on the callers queue after an `await ` on some actor method.
>> If you `await` on a non-actor-method though, you would have to changes queues manually if needed.
>> Any `actor` should have a `let actorQueue: DispatchQueue` property so that we can call in these cases:
>> ```await actorQueue.asyncCoroutine()``` as mentioned in the manifesto.
> Wouldn't that be really confusing though? That awaiting certain methods would bring us back to the actor's queue but awaiting others would require manual queue hopping? What if the compiler was to always generate the 'await actorQueue.asyncCoroutine()' queue hopping code after awaiting on an async/actor method?
I think we are not allowed to implicitly switch back to the actor's queue after awaiting non-actor methods. These might have been auto converted from Continuation-Passing-Style (CPS) to async/await style. With the `mainActor` idea from the manifesto, all existing code will run in some actor, so changing the queue semantics could break existing code.
Actually, I don’t find it confusing: when calling non-actor methods, you have to take care by yourself - as today. Calling actor methods instead, you don’t have to bother about this any longer - this is actually a big incentive to ‚actorify‘ many APIs ;-)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution