-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for registering factories on the main thread #174
Conversation
// thread using the knit generated resolver. If that call is not made on the main | ||
// thread then a crash will occur. | ||
@discardableResult | ||
public func register<Service>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've only added a single register function for now. I'll setup an ERB to generate them all in a future PR
f491f3a
to
82a60c7
Compare
.macOS(.v13), | ||
.macOS(.v14), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be somewhat nice to support back one version of macOS, was there an API you needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep error: 'assumeIsolated(_:file:line:)' is only available in macOS 14.0 or newer
. Technically we don't actually use that in the knit code, it's part of the additions that are used by the app but due to the way the package is setup it will fail the build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we move the register functions into Swinject
then we can drop back down.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok yeah let's bump the min platform version 👍
public func register<Service>( | ||
_ serviceType: Service.Type, | ||
name: String? = nil, | ||
factory: @escaping @MainActor (Resolver) -> Service |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When introducing this override will the Swift compiler always match closures without the @MainActor
attribute to the Swinject method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With adding @MainActor
the compiler will pick the default one and then fail. I can't find any way to have a @MainActor
function called without adding @MainActor
to the closure signature. Which is good because it is always there for the parser to identify.
3326444
to
16be759
Compare
16be759
to
8d3b336
Compare
This allows
container.register(ServiceA.self) { @MainActor in ServiceA() }
to be generated asAny other assembly registrations will then need to be marked as @mainactor in order to consume the resolver function. The structure can be extended to support other concurrency patterns like async in the future.