Skip to content

Commit

Permalink
removed self reference in async code
Browse files Browse the repository at this point in the history
  • Loading branch information
anonvt committed Nov 14, 2024
1 parent f3313be commit 0e7115b
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Sources/Topsort/Utils/FilePersistedValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,18 @@ public class FilePersistedValue<T: Codable> {
get { value }
set {
value = newValue
persist()
persist(value: newValue)
}
}

private func persist() {
private func persist(value: T?) {
serialQueue.async {
do {
let fileManager = FileManager.default
if fileManager.fileExists(atPath: self.storePath) {
try fileManager.removeItem(atPath: self.storePath)
}
guard let value = self.value
else { return }
guard value != nil else { return }
let data = try PropertyListEncoder().encode(PersistedValueWrapper(value: value))
let url = URL(fileURLWithPath: self.storePath)
try data.write(to: url)
Expand Down

0 comments on commit 0e7115b

Please sign in to comment.