Operating system requirement

Hello, my code does not work

import AsyncAlgorithms

@main
struct AsyncApp {
    static func main() async {
        if #available(macOS 9999, *) {
            await run()
        } else {
            print("OS error")
        }
    }
    
    @available(macOS 9999, *)
    static func run() async {
        let stream = KeyboardStream()
        for await line in stream.debounce(for: .seconds(0.5)) {
            print("line: \(line)")
        }
        print("end loop")
    }
    
}

It prints:

Building for debugging...
Build complete! (0.09s)
OS error

My OS is: 12.3.1, I download the latest Swift packet swift-5.7 and did export TOOLCHAINS=swift, so my swift version is /Library/Developer/Toolchains/swift-5.7-DEVELOPMENT-SNAPSHOT-2022-06-04-a.xctoolchain/usr/bin/swift-version
Should the package run or not?

In your code:

This will always be false (coz your os version is 12) so it goest to else branch and prints OS error.

The code actually works. You can see your async function result by removing @available(macOS 9999, *) and if #available(macOS 9999, *)

If I remove it, I get a compiler error here

    for await line in stream.debounce(for: .seconds(0.5))  { // 'debounce(for:tolerance:)' is only available in macOS 9999 or newer
        print("line: \(line)")
    }

Try newer version or just use main of AsyncAlgorithms.
The availability updated at Jun 14: Update availability to be in sync with Clock/Instant/Duration (#159) ยท apple/swift-async-algorithms@434591a ยท GitHub

At first glance, the package now does not compile at all

Has anyone been able to run this package? What is your system configuration?

It appears that you're attempting to use a swift.org toolchain that has the old 9999 availability for Clock and Duration, as well as macOS 12.x, which isn't supported. The new standard library types and hence the async algorithms features that use them require macOS 13.0 (currently in beta release).

CC @Philippe_Hausler for further comment and guidance.

3 Likes

As @scanon mentioned -- 9999 availability is what is set on nightly builds on swift.org, you can use those toolchains but you need to disable those availability checks with -Xfrontend -disable-availability-checking, and you can add this in Xcode in Swift extra compiler flags, or via SwiftPM on command line as swift build -Xswiftc -Xfrontend -Xswiftc -disable-availability-checking.

Though the real answer is to get an up-to-date OS and use its OS/toolchain/Xcode instead.

4 Likes