fixes issues where the scheduled timer failed

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

@ -500,8 +500,8 @@ public class StoredCollection<T: Storable>: SomeCollection {
/// Schedules a write operation
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)
}
}
@ -513,13 +513,15 @@ public class StoredCollection<T: Storable>: SomeCollection {
/// Writes all the items as a json array inside a file
@objc fileprivate func _write() {
do {
let jsonString: String = try self.items.jsonString()
try self.store.write(content: jsonString, fileName: T.fileName())
} catch {
Logger.error(error)
self.storeCenter.log(
message: "write failed for \(T.resourceName()): \(error.localizedDescription)")
DispatchQueue(label: "lestorage.queue.write", qos: .utility).async {
do {
let jsonString: String = try self.items.jsonString()
try self.store.write(content: jsonString, fileName: T.fileName())
} catch {
Logger.error(error)
self.storeCenter.log(
message: "write failed for \(T.resourceName()): \(error.localizedDescription)")
}
}
self._cleanTimer()
}

Loading…
Cancel
Save