[swift-evolution] [Concurrency] Async/Await

Martin Waitz tali at admingilde.org
Wed Aug 23 02:06:12 CDT 2017


> Am 22.08.2017 um 18:32 schrieb Joe Groff via swift-evolution <swift-evolution at swift.org>:
> The feature provides general delimited continuations. You could write an IteratorProtocol-conforming interface over a coroutine like this:
>  private func yield(_ value: T) async -> Void {
>    self.next = value
>    await suspendAsync { cont in
>      resume = cont
>    }
>  }
> This isn't ideal in a number of ways (awkward, not particularly efficient, and has the gotcha that the generator's `body` could suspend itself with something other than the `yield` operation, doesn't integrate with ownership in the way John proposes in the ownership manifesto), so it may not be a good idea, of course.

I still have trouble understanding how exactly suspendAsync is going to work.
Is the body called right away or is it put into some dispatch queue on another thread?
Does the continuation function return immediately (besides queueing suspendAsync to also return)?

How does this correlate with coroutines?
There is no extra stack for the coroutine (which runs the generator function), right?
In my mental model, the generator function is split into individual functions which are queued one after another, but reusing the same thread/stack, is this correct?

How would a generator feature without the mentioned shortcomings look like?

Thanks for any help in understanding how it works!
And thanks for all the great work, this looks like a nice basis for future Swift :-)

— Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170823/20b51a76/attachment.html>

More information about the swift-evolution mailing list