|
|
|
|
@ -34,6 +34,8 @@ actor ApiCallCollection<T: Storable>: SomeCallCollection { |
|
|
|
|
/// Indicates if the collection is currently retrying ApiCalls |
|
|
|
|
fileprivate var _isRetryingCalls: Bool = false |
|
|
|
|
|
|
|
|
|
fileprivate var _executionTask: Task<Void, any Error>? = nil |
|
|
|
|
|
|
|
|
|
/// Indicates whether the collection content has changed |
|
|
|
|
/// Initiates a write when true |
|
|
|
|
fileprivate var _hasChanged: Bool = false { |
|
|
|
|
@ -107,17 +109,20 @@ actor ApiCallCollection<T: Storable>: SomeCallCollection { |
|
|
|
|
self._hasChanged = true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
func findCallById(_ id: String) async -> (any SomeCall)? { |
|
|
|
|
return self.findById(id) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns the Api call associated with the provided id |
|
|
|
|
func findById(_ id: String) -> ApiCall<T>? { |
|
|
|
|
return self.items.first(where: { $0.id == id }) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Returns the Api call associated with the provided id |
|
|
|
|
func findCallById(_ id: String) async -> (any SomeCall)? { |
|
|
|
|
return self.findById(id) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Removes all objects in memory and deletes the JSON file |
|
|
|
|
func reset() { |
|
|
|
|
self._executionTask?.cancel() |
|
|
|
|
self.items.removeAll() |
|
|
|
|
|
|
|
|
|
do { |
|
|
|
|
@ -140,7 +145,7 @@ actor ApiCallCollection<T: Storable>: SomeCallCollection { |
|
|
|
|
self._isRetryingCalls = true |
|
|
|
|
self._attemptLoops += 1 |
|
|
|
|
|
|
|
|
|
Task { |
|
|
|
|
self._executionTask = Task { |
|
|
|
|
|
|
|
|
|
let delay = pow(2, self._attemptLoops) |
|
|
|
|
let seconds = NSDecimalNumber(decimal: delay).intValue |
|
|
|
|
@ -168,7 +173,6 @@ actor ApiCallCollection<T: Storable>: SomeCallCollection { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// MARK: - Synchronization |
|
|
|
|
@ -273,7 +277,7 @@ actor ApiCallCollection<T: Storable>: SomeCallCollection { |
|
|
|
|
default: |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
Logger.log("") |
|
|
|
|
// Logger.log("") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Returns the content of the API call file as a String |
|
|
|
|
|