fixes issues where the scheduled timer failed

sync3
Laurent 1 month ago
parent c8131d3009
commit 6f4dc9d5f5
  1. 4
      LeStorage/StoredCollection.swift

@ -500,8 +500,8 @@ public class StoredCollection<T: Storable>: SomeCollection {
/// Schedules a write operation /// Schedules a write operation
fileprivate func _scheduleWrite() { fileprivate func _scheduleWrite() {
DispatchQueue(label: "lestorage.queue.write", qos: .utility).asyncAndWait {
self._cleanTimer() self._cleanTimer()
DispatchQueue.main.async {
self._writingTimer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(self._write), userInfo: nil, repeats: false) self._writingTimer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(self._write), userInfo: nil, repeats: false)
} }
} }
@ -513,6 +513,7 @@ public class StoredCollection<T: Storable>: SomeCollection {
/// Writes all the items as a json array inside a file /// Writes all the items as a json array inside a file
@objc fileprivate func _write() { @objc fileprivate func _write() {
DispatchQueue(label: "lestorage.queue.write", qos: .utility).async {
do { do {
let jsonString: String = try self.items.jsonString() let jsonString: String = try self.items.jsonString()
try self.store.write(content: jsonString, fileName: T.fileName()) try self.store.write(content: jsonString, fileName: T.fileName())
@ -521,6 +522,7 @@ public class StoredCollection<T: Storable>: SomeCollection {
self.storeCenter.log( self.storeCenter.log(
message: "write failed for \(T.resourceName()): \(error.localizedDescription)") message: "write failed for \(T.resourceName()): \(error.localizedDescription)")
} }
}
self._cleanTimer() self._cleanTimer()
} }

Loading…
Cancel
Save