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:
@@ -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
|
||||||
|
if self.watcher == nil {
|
||||||
|
self.startWatcher(url)
|
||||||
|
}
|
||||||
|
|
||||||
// Watcher needs to be updated
|
// Watcher needs to be updated
|
||||||
if self.watcher.url != url || forceReload {
|
if self.watcher.url != url || forceReload {
|
||||||
self.watcher.disable()
|
self.watcher.disable()
|
||||||
self.watcher = nil
|
self.watcher = nil
|
||||||
Log.info("Watcher has stopped watching files. Starting new one...")
|
Log.info("Watcher has stopped watching files. Starting new one...")
|
||||||
startWatcher(url)
|
self.startWatcher(url)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user