Any reason why AsyncInitWrapper is not provided by Factory? #236
JonnyBeeGod
started this conversation in
General
Replies: 1 comment
-
Easiest method, actually, is to simple mark the initializer as nonisolated. @MainActor
private final class NonIsolatedMainActorType: Sendable {
nonisolated init() {}
func test() {}
}
extension Container {
fileprivate var nonisolatedMainActor: Factory<NonIsolatedMainActorType> {
self { NonIsolatedMainActorType() }
}
} Or you can simply use Task for the job. // Factory with Task
extension Container {
fileprivate var taskMainActor: Factory<Task<SomeMainActorType, Never>> {
self { Task { await SomeMainActorType() } }
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We have a lot of
@MainActor
annotated types we would like to resolve via Factory. When doing so we get compiler errors like "Call to main actor-isolated initializer 'init()' in a synchronous nonisolated context" in the registrations. Looking at the FactoryDemos you showed how to register those viaAsyncInitWrapper
, however this type is not provided by Factory. I am wondering what is the reason for this?Beta Was this translation helpful? Give feedback.
All reactions