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

Remove setter from Atomic to prevent API misuse, fix TSAN error in network interceptor #1538

Merged
merged 4 commits into from
Nov 25, 2020

Conversation

designatednerd
Copy link
Contributor

@martijnwalraven pointed out in #1531 that it's a little too easy to accidentally misuse the Atomic API as it stands now, particularly in terms of dealing with things like toggling a boolean or making changes to an array. This PR removes the setter wrapper for value, so that if you need to make changes, you can only change things by using mutate, which executes the changes in a block for safety.

I also fixed a thread sanitizer error in the Network interceptor around the cancellable that it holds onto. Once this and #1531 are merged, that should allow us to turn on thread sanitizer in tests permanently. 🤞

Copy link
Contributor

@martijnwalraven martijnwalraven left a comment

Choose a reason for hiding this comment

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

Great, looks good to me!

}

public func cancel() {
self.currentTask?.cancel()
guard let task = self.currentTask.value else {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems this could just be self.currentTask.value?.cancel(), but I assume you prefer this because you find it more readable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

somewhat, yep.

@designatednerd designatednerd merged commit bcefd92 into main Nov 25, 2020
@designatednerd designatednerd added this to the Next Release milestone Nov 30, 2020
@designatednerd designatednerd deleted the update/atomic-setup branch November 30, 2020 21:05
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