Improves the behaviour and fixes some issues with cancelling of Feedly operations.
This commit is contained in:
parent
b763a4bb52
commit
3ed5a43de3
|
@ -21,8 +21,8 @@ class FeedlyOperation: Operation {
|
||||||
func didFinish() {
|
func didFinish() {
|
||||||
assert(Thread.isMainThread)
|
assert(Thread.isMainThread)
|
||||||
assert(!isFinished, "Finished operation is attempting to finish again.")
|
assert(!isFinished, "Finished operation is attempting to finish again.")
|
||||||
self.isExecutingOperation = false
|
isExecutingOperation = false
|
||||||
self.isFinishedOperation = true
|
isFinishedOperation = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func didFinish(_ error: Error) {
|
func didFinish(_ error: Error) {
|
||||||
|
@ -33,16 +33,18 @@ class FeedlyOperation: Operation {
|
||||||
}
|
}
|
||||||
|
|
||||||
override func start() {
|
override func start() {
|
||||||
|
guard !isCancelled else {
|
||||||
|
isExecutingOperation = false
|
||||||
|
isFinishedOperation = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
isExecutingOperation = true
|
isExecutingOperation = true
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.main()
|
self.main()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func cancel() {
|
|
||||||
super.cancel()
|
|
||||||
}
|
|
||||||
|
|
||||||
override var isExecuting: Bool {
|
override var isExecuting: Bool {
|
||||||
return isExecutingOperation
|
return isExecutingOperation
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,10 +94,9 @@ final class FeedlySyncAllOperation: FeedlyOperation {
|
||||||
os_log(.debug, log: log, "Cancelling sync %{public}@", syncUUID.uuidString)
|
os_log(.debug, log: log, "Cancelling sync %{public}@", syncUUID.uuidString)
|
||||||
self.operationQueue.cancelAllOperations()
|
self.operationQueue.cancelAllOperations()
|
||||||
|
|
||||||
syncCompletionHandler?(.failure(URLError(.cancelled)))
|
super.cancel()
|
||||||
syncCompletionHandler = nil
|
|
||||||
|
|
||||||
self.didFinish()
|
didFinish()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func main() {
|
override func main() {
|
||||||
|
|
|
@ -96,13 +96,15 @@ final class FeedlySyncStarredArticlesOperation: FeedlyOperation, FeedlyOperation
|
||||||
}
|
}
|
||||||
|
|
||||||
override func cancel() {
|
override func cancel() {
|
||||||
|
os_log(.debug, log: log, "Canceling sync starred articles")
|
||||||
operationQueue.cancelAllOperations()
|
operationQueue.cancelAllOperations()
|
||||||
super.cancel()
|
super.cancel()
|
||||||
|
didFinish()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func main() {
|
override func main() {
|
||||||
guard !isCancelled else {
|
guard !isCancelled else {
|
||||||
didFinish()
|
// override of cancel calls didFinish().
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,6 +112,11 @@ final class FeedlySyncStarredArticlesOperation: FeedlyOperation, FeedlyOperation
|
||||||
}
|
}
|
||||||
|
|
||||||
func feedlyGetStreamContentsOperation(_ operation: FeedlyGetStreamContentsOperation, didGetContentsOf stream: FeedlyStream) {
|
func feedlyGetStreamContentsOperation(_ operation: FeedlyGetStreamContentsOperation, didGetContentsOf stream: FeedlyStream) {
|
||||||
|
guard !isCancelled else {
|
||||||
|
os_log(.debug, log: log, "Cancelled starred stream contents for %@", stream.id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
entryProvider.addEntries(from: operation)
|
entryProvider.addEntries(from: operation)
|
||||||
os_log(.debug, log: log, "Collecting %i items from %@", stream.items.count, stream.id)
|
os_log(.debug, log: log, "Collecting %i items from %@", stream.items.count, stream.id)
|
||||||
|
|
||||||
|
|
|
@ -42,13 +42,15 @@ final class FeedlySyncStreamContentsOperation: FeedlyOperation, FeedlyOperationD
|
||||||
}
|
}
|
||||||
|
|
||||||
override func cancel() {
|
override func cancel() {
|
||||||
|
os_log(.debug, log: log, "Canceling sync stream contents")
|
||||||
operationQueue.cancelAllOperations()
|
operationQueue.cancelAllOperations()
|
||||||
super.cancel()
|
super.cancel()
|
||||||
|
didFinish()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func main() {
|
override func main() {
|
||||||
guard !isCancelled else {
|
guard !isCancelled else {
|
||||||
didFinish()
|
// override of cancel calls didFinish().
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,6 +94,11 @@ final class FeedlySyncStreamContentsOperation: FeedlyOperation, FeedlyOperationD
|
||||||
}
|
}
|
||||||
|
|
||||||
func feedlyGetStreamContentsOperation(_ operation: FeedlyGetStreamContentsOperation, didGetContentsOf stream: FeedlyStream) {
|
func feedlyGetStreamContentsOperation(_ operation: FeedlyGetStreamContentsOperation, didGetContentsOf stream: FeedlyStream) {
|
||||||
|
guard !isCancelled else {
|
||||||
|
os_log(.debug, log: log, "Cancelled requesting page for %@", resource.id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
os_log(.debug, log: log, "Ingesting %i items from %@", stream.items.count, stream.id)
|
os_log(.debug, log: log, "Ingesting %i items from %@", stream.items.count, stream.id)
|
||||||
|
|
||||||
guard let continuation = stream.continuation else {
|
guard let continuation = stream.continuation else {
|
||||||
|
|
|
@ -77,13 +77,15 @@ final class FeedlySyncUnreadStatusesOperation: FeedlyOperation, FeedlyOperationD
|
||||||
}
|
}
|
||||||
|
|
||||||
override func cancel() {
|
override func cancel() {
|
||||||
|
os_log(.debug, log: log, "Canceling sync unread statuses")
|
||||||
operationQueue.cancelAllOperations()
|
operationQueue.cancelAllOperations()
|
||||||
super.cancel()
|
super.cancel()
|
||||||
|
didFinish()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func main() {
|
override func main() {
|
||||||
guard !isCancelled else {
|
guard !isCancelled else {
|
||||||
didFinish()
|
// override of cancel calls didFinish().
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,6 +93,11 @@ final class FeedlySyncUnreadStatusesOperation: FeedlyOperation, FeedlyOperationD
|
||||||
}
|
}
|
||||||
|
|
||||||
func feedlyGetStreamIdsOperation(_ operation: FeedlyGetStreamIdsOperation, didGet streamIds: FeedlyStreamIds) {
|
func feedlyGetStreamIdsOperation(_ operation: FeedlyGetStreamIdsOperation, didGet streamIds: FeedlyStreamIds) {
|
||||||
|
guard !isCancelled else {
|
||||||
|
os_log(.debug, log: log, "Cancelled unread stream ids.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
os_log(.debug, log: log, "Collecting %i unread article ids from %@", streamIds.ids.count, resource.id)
|
os_log(.debug, log: log, "Collecting %i unread article ids from %@", streamIds.ids.count, resource.id)
|
||||||
unreadEntryIdsProvider.addEntryIds(from: operation)
|
unreadEntryIdsProvider.addEntryIds(from: operation)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue