Skip to content
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

Isolate state and send to main actor #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gordonbrander
Copy link
Collaborator

Fixes #34

This should make it impossible to update the state outside the main thread (make it impossible to trigger a purple warning).

Copy link
Collaborator Author

@gordonbrander gordonbrander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make changes to the approach.


func send(_ action: Model.Action) -> Void
@MainActor func send(_ action: Model.Action) -> Void
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than isolating send to main actor, we may want to allow send to be nonisolated, and have a separate main-actor isolated transact method which does the actual transaction. This would give us more flexibility in where we can call send, while ensuring state changes only happen on main.

@@ -159,9 +159,9 @@ public struct Update<Model: ModelProtocol> {
public protocol StoreProtocol {
associatedtype Model: ModelProtocol

var state: Model { get }
@MainActor var state: Model { get }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get-only property should be nonisolated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Force store state change onto main actor
1 participant