Open fwcd opened 1 month ago
I have a question for you: what need do you have that warrants an async initializer? I'm not questioning its importance but rather the context in which you're using it. If it's a UI-related task where an async operation helps complete the process, I would think that a synchronous initializer might be better suited, as it allows you to provide a visual indication to the user that data is loading.
I find async initializers to be pretty useful for writing wrappers around web APIs. Authenticating within the initializer means an instance always represents an authenticated state, which is really convenient, since the methods can now operate under that assumption. That makes it more type safe too, since there is no instance to call anything on when logged out. Wrapping the instance in an optional e.g. would make sure that the logged out case is always handled when chaining some method call. Sure, in practice there's still stuff that can go wrong, tokens can expire, but those are edge cases that are perhaps better served via errors.
Oh, interesting—that makes sense! Although things can still go wrong between initialization and making authorized requests, such as token expiration, using an async initializer seems beneficial. With it, you likely avoid the need to add property wrappers to every method just to ensure the user is authorized. This way, you can avoid running authorization checks or middleware on every function call, correct?
Does this align with your thought process?
Description
Conforming an actor to a protocol with async initializers using synchronous initializers seems to crash the compiler using the new Swift 6/Xcode 16 toolchain.
Reproduction
Stack dump
Expected behavior
This shouldn't crash. As a workaround,
X
could mark the initializerasync
too.Environment
swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2) Target: arm64-apple-macosx15.0
Additional information
No response