The compiler could rewrite this:
print(await dataModel.getNumberOfEntries())
actor func getNumberOfEntries() -> Int
{
return theList.count
}
as this:
dataModel.getNumberOfEntries(_internalQueue) { count in
print(count)
}
actor func getNumberOfEntries(queue: DispatchQueue, handler: Int -> Void) ->
Void
{
_internalQueue.async {
let count = theList.count
queue.async {
handler(count)
}
}
}
There is another problem that bothers me, if the function were to await on
another actor (and therefore dispatch away from its _internalQueue), how would
you guarantee that "only one message is processed by the actor at a time". You
would need to somehow prevent the internal queue from processing other messages.
Thomas
> On 18 Aug 2017, at 17:13, Johannes Weiß via swift-evolution
> <[email protected]> wrote:
>
> GCD doesn't actually allow you to dispatch back to the original queue, so I
> find it unclear how you'd achieve that. IMHO the main reason is that
> conceptually at a given time you can be on more than one queue (nested
> q.sync{}/target queues). So which is 'the' current queue?
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution