Can I use await on Big Sur?

Seems async/detach are available on Monterey only, so how can I use it on Big Sur? The following code won't compile:

func computeSomething() async -> Int {
    42
}

async {
    print(await computeSomething())
}

Clear enough error is:

'async(priority:operation:)' is only available in macOS 12.0 or newer

It seems that I can declare async functions, and write code using await, but I will never be able to close the gap between async and sync code, as I would need a Task for that.

I'm curious about the following:

  • will I be able to use await on Big Sur? Where/how can I close the gap and move from async to sync code?
  • given that the structured concurrency stuff is a language characteristic, why do I run into build errors related to OS versions?

Thanks,

Edit: I'm using Xcode 13.0 beta

1 Like

There was a big thread about this question a few weeks ago. In that thread, Ted Kremenek explained:

Concurrency requires runtime support that does not backward deploy. The release notes imply that this is an "issue" that just needs to be fixed. It's not. It's a feature that would need to be implemented. At this time, folks should assume that concurrency does not backward deploy. That said, everyone is aware of the value of it doing so, and is something that is being explored/considered.

The reason it doesn’t backwards deploy is that parts of the concurrency feature are implemented in Grand Central Dispatch and other parts of the OS. (The surface-level concurrency APIs are also shipped in the OS, but we deliberately put them in a separate binary so we’d be ready to back-deploy them if the other technical barriers could be surmounted.) It’s not clear if concurrency can be cut loose from these changes or if the results would work well enough to recommend using. We’re exploring that, but for now you should assume the answer will be “no”.

7 Likes

Thanks @beccadax, for the link and the extra details. This means that Linux/Windows will also not be able to benefit from the new language constructs?

On Linux and Windows, the Corelibs Dispatch framework is packaged with Swift (and shipped with your app if you’re shipping binaries). That means Swift 5.5 can include an upgraded Dispatch framework that supports concurrency. Corelibs Dispatch doesn’t depend on any changes deeper in the OS; the trade-off is that Dispatch on these platforms is not as “smart” (particularly, it’s not as aware of overall system load) as Dispatch on macOS is.

3 Likes

That is amazing Becca :) (it is, no joke), but does it mean we can ask for a less smart version of LibDispatch we can package with our apps and get the backdeployed to iOS 14 using full concurrency ;)?

1 Like

It's funny how Apple engineers kept advocating in WWDC '21 sessions about how the Structured Concurrency in Swift 5.5 is better than GCD synchronization, and in turn the newly introduced concurrency concepts have a strong dependency on CGD :)

Hope the Swift team finds a solution to backport the concurrency concepts to older OS'es, it would be a shame for most of Swift developers to not be able to use them due to having to support older OS'es in their apps.