[swift-evolution] [Concurrency] Async/Await

Brent Royal-Gordon brent at architechies.com
Tue Aug 22 04:07:46 CDT 2017

> On Aug 21, 2017, at 10:47 PM, Jonathan Hull via swift-evolution <swift-evolution at swift.org> wrote:
> I am finding that I DO NOT understand beginAsync.  At first I thought it was the async/await version of 'do{}’, but as others are giving examples which use it in different ways, I find I don’t actually know how it works… because the examples aren’t using it that way.  
> Can anyone give a layman’s explanation of beginAsync.  That might actually help with the bike shedding.  If you can’t explain something simply, then you don’t really understand it… and if you don’t understand it, you can’t really give it an intuitive name.

This would be my explanation:

	`beginAsync` runs the provided async function up until the point where it needs to `await` a result; it then returns so that you can do other work. The function will resume later, after whatever result it's `await`ing has been returned.

A slightly more technical explanation would note that `beginAsync` runs the function until it, or one of its callees, calls `suspendAsync` with a function that returns without calling the continuation function it was passed. It is `suspendAsync` being called and returning without calling the continuation that causes all the functions above it, all the way up to the one passed to `beginAsync`, to return.

Brent Royal-Gordon

More information about the swift-evolution mailing list