Monday, December 7, 2020

Swift Proposal for async/await

SE-0296 (via Doug Gregor):

This design introduces a coroutine model to Swift. Functions can opt into being async, allowing the programmer to compose complex logic involving asynchronous operations using the normal control-flow mechanisms. The compiler is responsible for translating an asynchronous function into an appropriate set of closures and state machines.

This proposal defines the semantics of asynchronous functions. However, it does not provide concurrency: that is covered by a separate proposal to introduce structured concurrency, which associates asynchronous functions with concurrently-executing tasks and provides APIs for creating, querying, and cancelling tasks.

[…]

Because only async code can call other async code, this proposal provides no way to initiate asynchronous code. This is intentional: all asynchronous code runs within the context of a “task”, a notion which is defined in the Structured Concurrency proposal. That proposal provides the ability to define asynchronous entry points to the program via @main […]

Previously:

Update (2020-12-08): Eneko Alonso:

The above two extensions allow launching an async task from a DispatchQueue, with or without a DispatchGroup.

Update (2020-12-24): Ben Cohen:

The async/await proposal is accepted!

The first of a series of Concurrency proposals coming to Swift Evolution. @dgregor79 put together a dependency graph

Comments RSS · Twitter

Leave a Comment