|
|
|
|
@ -18,7 +18,7 @@ protocol SomeCollection: Identifiable { |
|
|
|
|
func deleteById(_ id: String) throws |
|
|
|
|
func deleteApiCallById(_ id: String) throws |
|
|
|
|
func reset() |
|
|
|
|
func loadDataFromServerIfAllowed() throws |
|
|
|
|
func loadDataFromServerIfAllowed() async throws |
|
|
|
|
var synchronized: Bool { get } |
|
|
|
|
func hasPendingAPICalls() -> Bool |
|
|
|
|
} |
|
|
|
|
@ -116,7 +116,9 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti |
|
|
|
|
|
|
|
|
|
do { |
|
|
|
|
if self._inMemory { |
|
|
|
|
try self.loadDataFromServerIfAllowed() |
|
|
|
|
Task { |
|
|
|
|
try await self.loadDataFromServerIfAllowed() |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
try self._loadFromFile() |
|
|
|
|
} |
|
|
|
|
@ -171,18 +173,16 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Retrieves the data from the server and loads it into the items array |
|
|
|
|
public func loadDataFromServerIfAllowed() throws { |
|
|
|
|
public func loadDataFromServerIfAllowed() async throws { |
|
|
|
|
guard self.synchronized, !(self is StoredSingleton<T>) else { |
|
|
|
|
throw StoreError.unSynchronizedCollection |
|
|
|
|
} |
|
|
|
|
Task { |
|
|
|
|
do { |
|
|
|
|
let items: [T] = try await self._store.getItems() |
|
|
|
|
try self._addOrUpdate(contentOfs: items, shouldSync: false) |
|
|
|
|
self._hasChanged = true |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
do { |
|
|
|
|
let items: [T] = try await self._store.getItems() |
|
|
|
|
try self._addOrUpdate(contentOfs: items, shouldSync: false) |
|
|
|
|
self._hasChanged = true |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|