Stores have been required to be on the main thread for a long time, but because they predate Swift concurrency, we adopted a model that was standard at the time: pushing that responsibility on the user, and warning them when we detect access off the main thread.
This PR adopts a more modern sensibility by adding @preconcurrency @MainActor to APIs that we require to be on the main thread. We'll use @preconcurrency to avoid breaking changes, but the main advantages:
It will prevent stores from being created or interacted with off the main thread, and it will warn the user at compile time if they attempt to do so without awaiting.
Tests no longer need to be marked @MainActor for the TestStore.
This PR should not prevent us from providing stores the ability to work on non-main actors, and should actually help us get closer to that goal.
Stores have been required to be on the main thread for a long time, but because they predate Swift concurrency, we adopted a model that was standard at the time: pushing that responsibility on the user, and warning them when we detect access off the main thread.
This PR adopts a more modern sensibility by adding
@preconcurrency @MainActor
to APIs that we require to be on the main thread. We'll use@preconcurrency
to avoid breaking changes, but the main advantages:await
ing.@MainActor
for theTestStore
.This PR should not prevent us from providing stores the ability to work on non-main actors, and should actually help us get closer to that goal.