From 51faf77e59672397cf4a920f37f6fb0e5cb6d298 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Tue, 31 Dec 2019 15:40:05 -0800 Subject: [PATCH] Update isExecuting and isFinished in a way that should make NSOperationQueue happy. Hopefully this fixes a mystery crash bug. --- .../Feedly/Operations/FeedlyOperation.swift | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/Frameworks/Account/Feedly/Operations/FeedlyOperation.swift b/Frameworks/Account/Feedly/Operations/FeedlyOperation.swift index f1ea40369..2057fe657 100644 --- a/Frameworks/Account/Feedly/Operations/FeedlyOperation.swift +++ b/Frameworks/Account/Feedly/Operations/FeedlyOperation.swift @@ -35,8 +35,7 @@ class FeedlyOperation: Operation { downloadProgress = nil - isExecutingOperation = false - isFinishedOperation = true + updateExecutingAndFinished(false, true) } func didFinish(_ error: Error) { @@ -58,9 +57,8 @@ class FeedlyOperation: Operation { override func start() { guard !isCancelled else { - isExecutingOperation = false - isFinishedOperation = true - + updateExecutingAndFinished(false, true) + if downloadProgress != nil { DispatchQueue.main.async { self.downloadProgress = nil @@ -69,8 +67,8 @@ class FeedlyOperation: Operation { return } - - isExecutingOperation = true + + updateExecutingAndFinished(true, false) DispatchQueue.main.async { self.main() } @@ -80,24 +78,30 @@ class FeedlyOperation: Operation { return isExecutingOperation } - private var isExecutingOperation = false { - willSet { - willChangeValue(for: \.isExecuting) - } - didSet { - didChangeValue(for: \.isExecuting) - } - } - override var isFinished: Bool { return isFinishedOperation } - - private var isFinishedOperation = false { - willSet { + + private var isExecutingOperation = false + private var isFinishedOperation = false + + private func updateExecutingAndFinished(_ executing: Bool, _ finished: Bool) { + let isExecutingDidChange = executing != isExecutingOperation + let isFinishedDidChange = finished != isFinishedOperation + + if isFinishedDidChange { willChangeValue(for: \.isFinished) } - didSet { + if isExecutingDidChange { + willChangeValue(for: \.isExecuting) + } + isExecutingOperation = executing + isFinishedOperation = finished + + if isExecutingDidChange { + didChangeValue(for: \.isExecuting) + } + if isFinishedDidChange { didChangeValue(for: \.isFinished) } }