-
Notifications
You must be signed in to change notification settings - Fork 227
fix(amplify): change reset method #866
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
Conversation
diegocstn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we maybe use the partition(by:) method to get a partitioned array with .logging and .hub cases at the end?
| let group = DispatchGroup() | ||
|
|
||
| for categoryType in CategoryType.allCases { | ||
| let manuallyResetCategories = [CategoryType.logging, .hub] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: let manuallyResetCategories: [CategoryType] = [.logging, .hub]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Synced offline. You can take a look again.
| case .hub, .logging: | ||
| // should be waited until other finish resetting | ||
| break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this class has a lot of hard coding logging and hub categories, maybe you can isolate these two categories that you can reuse in the rest of the code, like
let resetLastCategories = [CategoryType.hub, .logging]
then you can filter before line 25 by let resetFirstCategories = CategoryType.allCases.filter { !resetLastCategories.contains($0) }
With this, would you be able to avoid empty switch cases, similar to code like this?
for categoryType in resetFirstCategories {
reset(categoryType.category, in: group) { group.leave() }
}
group.wait()
for categoryType in resetLastCategories {
reset(categoryType.category, in: group) { group.leave() }
}
group.wait()
Description of changes:
The existing implementation of
Amplify.reset()is to callreset()on every Categories and put them in globalDispatchGroupwhich might cause a race condition. For example, during theDataStorereset process, it depends onHubto dispatch some event, but at that point,Hubmight already been reset and cause a precondition failure on https://github.com/aws-amplify/amplify-ios/blob/main/Amplify/Categories/Hub/HubCategory.swift#L44The change I made is:
reset()onloggingandhubcategories should be called when other categories finish resetting.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.