Resolver icon indicating copy to clipboard operation
Resolver copied to clipboard

Actor Based Register Method

Open Zoha131 opened this issue 3 years ago • 1 comments

When I try to register an object which is marked as @MainActor then it gives the following error

Call to main actor-isolated initializer 'init()' in a synchronous nonisolated context

Is it possible to support this kind of register method?

Zoha131 avatar Sep 19 '22 05:09 Zoha131

This was discussed at some length in Factory. The two solutions are to a) don't do that, or b) mark your init as nonisolated.

The best solution is a) don't mark the entire class as @MainActor. It's usually not necessary. Just mark the async functions @MainActor as needed.

https://github.com/hmlongco/Factory/issues/21

hmlongco avatar Sep 19 '22 05:09 hmlongco