1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-11-09 13:10:24 +01:00

🐛 Fix retain cycle due to threading issue

This commit is contained in:
2022-02-08 22:19:32 +01:00
parent cdc082071d
commit 7cd50aed7b

View File

@@ -30,17 +30,22 @@ extension App {
func handlePhpConfigWatcher(forceReload: Bool = false) { func handlePhpConfigWatcher(forceReload: Bool = false) {
let url = URL(fileURLWithPath: "\(Paths.etcPath)/php/\(PhpEnv.phpInstall.version.short)") let url = URL(fileURLWithPath: "\(Paths.etcPath)/php/\(PhpEnv.phpInstall.version.short)")
// Watcher needs to be created // Check whether the watcher exists and schedule on the main thread
if self.watcher == nil { // if we don't consistently do this, the app will create duplicate watchers
startWatcher(url) // due to timing issues, which creates retain cycles.
} DispatchQueue.main.async {
// Watcher needs to be created
// Watcher needs to be updated if self.watcher == nil {
if self.watcher.url != url || forceReload { self.startWatcher(url)
self.watcher.disable() }
self.watcher = nil
Log.info("Watcher has stopped watching files. Starting new one...") // Watcher needs to be updated
startWatcher(url) if self.watcher.url != url || forceReload {
self.watcher.disable()
self.watcher = nil
Log.info("Watcher has stopped watching files. Starting new one...")
self.startWatcher(url)
}
} }
} }