sync2
Laurent 12 months ago
parent b9a5e7c482
commit d3431c0c55
  1. 3
      LeStorage/StoreCenter.swift
  2. 6
      LeStorage/StoredCollection.swift

@ -378,6 +378,7 @@ public class StoreCenter {
/// - instance: an object to insert
func sendInsertion<T: Storable>(_ instance: T) async throws -> T? {
guard self._canSynchronise() else {
StoreCenter.main.log(message: "cannot send insert: \(T.resourceName()), \(StoreCenter.main.userName() ?? "no user")")
return nil
}
return try await self.apiCallCollection().sendInsertion(instance)
@ -388,6 +389,7 @@ public class StoreCenter {
/// - instance: an object to update
func sendUpdate<T: Storable>(_ instance: T) async throws -> T? {
guard self._canSynchronise() else {
StoreCenter.main.log(message: "cannot send update: \(T.resourceName()), \(StoreCenter.main.userName() ?? "no user")")
return nil
}
return try await self.apiCallCollection().sendUpdate(instance)
@ -398,6 +400,7 @@ public class StoreCenter {
/// - instance: an object to delete
func sendDeletion<T: Storable>(_ instance: T) async throws {
guard self._canSynchronise() else {
StoreCenter.main.log(message: "cannot send delete: \(T.resourceName()), \(StoreCenter.main.userName() ?? "no user")")
return
}
try await self.apiCallCollection().sendDeletion(instance)

@ -421,6 +421,7 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti
/// - instance: the object to POST
fileprivate func _sendInsertionIfNecessary(_ instance: T) {
guard self.synchronized else {
StoreCenter.main.log(message: "cannot send insert: \(T.resourceName()), \(StoreCenter.main.userName() ?? "no user") : sync = \(self.synchronized)")
return
}
Task {
@ -429,6 +430,7 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti
self.updateFromServerInstance(result)
}
} catch {
StoreCenter.main.log(message: error.localizedDescription)
Logger.error(error)
}
}
@ -450,12 +452,14 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti
/// - instance: the object to PUT
fileprivate func _sendUpdateIfNecessary(_ instance: T) {
guard self.synchronized, self._sendsUpdate else {
StoreCenter.main.log(message: "cannot send update: \(T.resourceName()), \(StoreCenter.main.userName() ?? "no user") : sync = \(self.synchronized), self._sendsUpdate = \(self._sendsUpdate)")
return
}
Task {
do {
try await self._store.sendUpdate(instance)
} catch {
StoreCenter.main.log(message: error.localizedDescription)
Logger.error(error)
}
}
@ -466,12 +470,14 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti
/// - instance: the object to DELETE
fileprivate func _sendDeletionIfNecessary(_ instance: T) {
guard self.synchronized else {
StoreCenter.main.log(message: "cannot send delete: \(T.resourceName()), \(StoreCenter.main.userName() ?? "no user") : sync = \(self.synchronized)")
return
}
Task {
do {
try await self._store.sendDeletion(instance)
} catch {
StoreCenter.main.log(message: error.localizedDescription)
Logger.error(error)
}
}

Loading…
Cancel
Save