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

Add variadic generics version of Defaults.updates() #191

Merged
merged 1 commit into from
Oct 4, 2024

Conversation

sindresorhus
Copy link
Owner

No description provided.

}

for key in repeat (each keys) {
let observation = DefaultsObservation(object: key.suite, key: key.name) { _, _ in
Copy link
Owner Author

Choose a reason for hiding this comment

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

Note: I'm intentionally not using CompositeDefaultsObservation for simplicity, as it's not really needed here.

let immutableObservations = observations

continuation.onTermination = { _ in
// `invalidate()` should be thread-safe, but it is not in practice.
Copy link
Collaborator

@hank121314 hank121314 Oct 1, 2024

Choose a reason for hiding this comment

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

Curious about this. I thought that invalidate() would be thread-safe with Lock,
Should we use DispatchQueue.sync instead inside the DefaultsObservation?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I'm not 100% sure. I have seen KVO crashes in some of my apps that may have been caused by some threading problems in macOS. I prefer to keep it limited to this code until I can 100% confirm it. This is just a precaution.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Got it! Thanks for the explanation!

@sindresorhus sindresorhus merged commit a89f799 into main Oct 4, 2024
4 checks passed
@sindresorhus sindresorhus deleted the updates-variadic branch October 4, 2024 10:27
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