Fix bug where HTTP requests were incorrectly cancelled#168
Open
FelixSFD wants to merge 3 commits intosupergeorg:grocy_mobile_2_xfrom
Open
Fix bug where HTTP requests were incorrectly cancelled#168FelixSFD wants to merge 3 commits intosupergeorg:grocy_mobile_2_xfrom
FelixSFD wants to merge 3 commits intosupergeorg:grocy_mobile_2_xfrom
Conversation
Author
|
@supergeorg tested it in the simulator and on my iPhone 13 mini and the bug seems to be fixed without breaking anything. But I think it's a good idea, if an experienced user would test as well, because I'm quite new to Grocy and might have missed something. |
Owner
|
Well, I am unsure if this is the best solution. This works because the cancellation is not implemented. I will check if ObservedObject is better than StateObject and will adapt the code accordingly. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
hopefully fixes #167
First, I changed the HTTP call from
.data()to.dataTask()with a completion handler. I did this, because I couldn't find out, which exact line was throwing the exception, when the request was cancelled.Because I didn't want to change the rest of the class, I wrapped this new call inside
withCheckedThrowingContinuation()to turn this into an async call.This didn't fix the issue completely, because there was a new warning in the log:
This error told me, what happened to the running tasks when navigating quickly: Something is wrong with the memory management of this class.
So I switched the property
grocyVMin the views from@SteteObjectto@ObservedObject, which is recommended for properties that are not created inside the view, but injected instead: https://www.avanderlee.com/swiftui/stateobject-observedobject-differences/#should-i-use-stateobject-for-all-views-using-the-same-instance