Update isExecuting and isFinished in a way that should make NSOperationQueue happy. Hopefully this fixes a mystery crash bug.
This commit is contained in:
parent
8a85b18d09
commit
51faf77e59
|
@ -35,8 +35,7 @@ class FeedlyOperation: Operation {
|
||||||
|
|
||||||
downloadProgress = nil
|
downloadProgress = nil
|
||||||
|
|
||||||
isExecutingOperation = false
|
updateExecutingAndFinished(false, true)
|
||||||
isFinishedOperation = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func didFinish(_ error: Error) {
|
func didFinish(_ error: Error) {
|
||||||
|
@ -58,8 +57,7 @@ class FeedlyOperation: Operation {
|
||||||
|
|
||||||
override func start() {
|
override func start() {
|
||||||
guard !isCancelled else {
|
guard !isCancelled else {
|
||||||
isExecutingOperation = false
|
updateExecutingAndFinished(false, true)
|
||||||
isFinishedOperation = true
|
|
||||||
|
|
||||||
if downloadProgress != nil {
|
if downloadProgress != nil {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
@ -70,7 +68,7 @@ class FeedlyOperation: Operation {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
isExecutingOperation = true
|
updateExecutingAndFinished(true, false)
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.main()
|
self.main()
|
||||||
}
|
}
|
||||||
|
@ -80,24 +78,30 @@ class FeedlyOperation: Operation {
|
||||||
return isExecutingOperation
|
return isExecutingOperation
|
||||||
}
|
}
|
||||||
|
|
||||||
private var isExecutingOperation = false {
|
|
||||||
willSet {
|
|
||||||
willChangeValue(for: \.isExecuting)
|
|
||||||
}
|
|
||||||
didSet {
|
|
||||||
didChangeValue(for: \.isExecuting)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override var isFinished: Bool {
|
override var isFinished: Bool {
|
||||||
return isFinishedOperation
|
return isFinishedOperation
|
||||||
}
|
}
|
||||||
|
|
||||||
private var isFinishedOperation = false {
|
private var isExecutingOperation = false
|
||||||
willSet {
|
private var isFinishedOperation = false
|
||||||
|
|
||||||
|
private func updateExecutingAndFinished(_ executing: Bool, _ finished: Bool) {
|
||||||
|
let isExecutingDidChange = executing != isExecutingOperation
|
||||||
|
let isFinishedDidChange = finished != isFinishedOperation
|
||||||
|
|
||||||
|
if isFinishedDidChange {
|
||||||
willChangeValue(for: \.isFinished)
|
willChangeValue(for: \.isFinished)
|
||||||
}
|
}
|
||||||
didSet {
|
if isExecutingDidChange {
|
||||||
|
willChangeValue(for: \.isExecuting)
|
||||||
|
}
|
||||||
|
isExecutingOperation = executing
|
||||||
|
isFinishedOperation = finished
|
||||||
|
|
||||||
|
if isExecutingDidChange {
|
||||||
|
didChangeValue(for: \.isExecuting)
|
||||||
|
}
|
||||||
|
if isFinishedDidChange {
|
||||||
didChangeValue(for: \.isFinished)
|
didChangeValue(for: \.isFinished)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue