Is `async let` safe to use in `main()`?

i’m finding that this simple program with an async let in the main function is segfaulting on debug builds:

@main 
enum Main 
{
    static 
    func foo() async -> [Void]
    {
        try? await Task.sleep(nanoseconds: 1)
        return []
    }
    static 
    func main() async
    {
        async let task:Void = 
        {
            () async -> () in 
            try? await Task.sleep(nanoseconds: 1)
        }()
        while true 
        {
            let _:[Void] = await Self.foo()
        }
    }
}

I’ve run into similar issues while using Task Groups in main, so i’m wondering if the same applies to async let? or is this just a bug?

1 Like
Terms of Service

Privacy Policy

Cookie Policy