Grocy-SwiftUI
Grocy-SwiftUI copied to clipboard
Fix bug where HTTP requests were incorrectly cancelled
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:
SWIFT TASK CONTINUATION MISUSE [...] leaked its continuation!
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 grocyVM
in the views from @SteteObject
to @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