fix(apple): Ensure resources are updated on MainActor#8064
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
thomaseizinger
left a comment
There was a problem hiding this comment.
This seems very brittle. Is there no better way to enforce this?
The compiler usually catches these. Unfortunately in this case it didn't, presumably because it's a callback. We did receive a runtime warning though in the logs, which is how I caught it. |
Can we establish a pattern where access to these fields always need to go through annotated functions or something like that? |
Hm yeah, I think we can actually mark this callback closure |
Followup to the discussion on #8064. By annotating the callback that updates our Resources `@MainActor`, the compiler will correctly warn us when we call it from a non-isolated context.
This fixes a bug introduced in db655dd that could lead to a crash or undefined behavior because it potentially updates resources (a
@Publishedobject) from a background thread.UI updates must occur on the main thread only.