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

Wrap store.send in Task {} #46

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

bfollington
Copy link

This significantly improves UI responsiveness in the main Subconscious app.

@@ -352,14 +352,20 @@ where Model: ModelProtocol
/// `send(_:)` is run *synchronously*. It is up to you to guarantee it is
/// run on main thread when SwiftUI is being used.
public func send(_ action: Model.Action) {
DispatchQueue.main.async { @MainActor in
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason we use this instead of the Task interface?

DispatchQueue is part of the old Grand Central Dispatch async API and does not coordinate with Swift's concurrency green thread implementation. Best avoided.

Copy link
Author

Choose a reason for hiding this comment

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

I'm having trouble getting the tests to consistently pass using Task { @MainActor in }, but on further experimentation this seems to be an issue regardless of approach.

Each test passes individually but running them together has them all competing to schedule tasks. Let's chat about the best approach on a call.

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.

2 participants