Update isExecuting and isFinished in a way that should make NSOperationQueue happy. Hopefully this fixes a mystery crash bug.

This commit is contained in:
Brent Simmons 2019-12-31 15:40:05 -08:00
parent 8a85b18d09
commit 51faf77e59
1 changed files with 24 additions and 20 deletions

View File

@ -35,8 +35,7 @@ class FeedlyOperation: Operation {
downloadProgress = nil
isExecutingOperation = false
isFinishedOperation = true
updateExecutingAndFinished(false, true)
}
func didFinish(_ error: Error) {
@ -58,8 +57,7 @@ class FeedlyOperation: Operation {
override func start() {
guard !isCancelled else {
isExecutingOperation = false
isFinishedOperation = true
updateExecutingAndFinished(false, true)
if downloadProgress != nil {
DispatchQueue.main.async {
@ -70,7 +68,7 @@ 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)
}
}