From 63c910e2a98a36045e806769ae11181fd2787631 Mon Sep 17 00:00:00 2001 From: Guilherme Pimenta Date: Wed, 13 Nov 2024 21:05:10 -0300 Subject: [PATCH] removed self reference in async code --- Sources/Topsort/Utils/FilePersistedValue.swift | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Sources/Topsort/Utils/FilePersistedValue.swift b/Sources/Topsort/Utils/FilePersistedValue.swift index e30fd17..f333db8 100644 --- a/Sources/Topsort/Utils/FilePersistedValue.swift +++ b/Sources/Topsort/Utils/FilePersistedValue.swift @@ -26,19 +26,18 @@ public class FilePersistedValue { 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)