Merge pull request #1295 from kielgillard/cancellation-improvements

Improves the behaviour and fixes some issues…
This commit is contained in:
Maurice Parker 2019-11-14 15:40:28 -06:00 committed by GitHub
commit a96c5f34ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 12 deletions

View File

@ -21,8 +21,8 @@ class FeedlyOperation: Operation {
func didFinish() {
assert(Thread.isMainThread)
assert(!isFinished, "Finished operation is attempting to finish again.")
self.isExecutingOperation = false
self.isFinishedOperation = true
isExecutingOperation = false
isFinishedOperation = true
}
func didFinish(_ error: Error) {
@ -33,16 +33,18 @@ class FeedlyOperation: Operation {
}
override func start() {
guard !isCancelled else {
isExecutingOperation = false
isFinishedOperation = true
return
}
isExecutingOperation = true
DispatchQueue.main.async {
self.main()
}
}
override func cancel() {
super.cancel()
}
override var isExecuting: Bool {
return isExecutingOperation
}

View File

@ -94,10 +94,9 @@ final class FeedlySyncAllOperation: FeedlyOperation {
os_log(.debug, log: log, "Cancelling sync %{public}@", syncUUID.uuidString)
self.operationQueue.cancelAllOperations()
syncCompletionHandler?(.failure(URLError(.cancelled)))
syncCompletionHandler = nil
super.cancel()
self.didFinish()
didFinish()
}
override func main() {

View File

@ -96,13 +96,15 @@ final class FeedlySyncStarredArticlesOperation: FeedlyOperation, FeedlyOperation
}
override func cancel() {
os_log(.debug, log: log, "Canceling sync starred articles")
operationQueue.cancelAllOperations()
super.cancel()
didFinish()
}
override func main() {
guard !isCancelled else {
didFinish()
// override of cancel calls didFinish().
return
}
@ -110,6 +112,11 @@ final class FeedlySyncStarredArticlesOperation: FeedlyOperation, FeedlyOperation
}
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)
os_log(.debug, log: log, "Collecting %i items from %@", stream.items.count, stream.id)

View File

@ -42,13 +42,15 @@ final class FeedlySyncStreamContentsOperation: FeedlyOperation, FeedlyOperationD
}
override func cancel() {
os_log(.debug, log: log, "Canceling sync stream contents")
operationQueue.cancelAllOperations()
super.cancel()
didFinish()
}
override func main() {
guard !isCancelled else {
didFinish()
// override of cancel calls didFinish().
return
}
@ -92,6 +94,11 @@ final class FeedlySyncStreamContentsOperation: FeedlyOperation, FeedlyOperationD
}
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)
guard let continuation = stream.continuation else {

View File

@ -77,13 +77,15 @@ final class FeedlySyncUnreadStatusesOperation: FeedlyOperation, FeedlyOperationD
}
override func cancel() {
os_log(.debug, log: log, "Canceling sync unread statuses")
operationQueue.cancelAllOperations()
super.cancel()
didFinish()
}
override func main() {
guard !isCancelled else {
didFinish()
// override of cancel calls didFinish().
return
}
@ -91,6 +93,11 @@ final class FeedlySyncUnreadStatusesOperation: FeedlyOperation, FeedlyOperationD
}
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)
unreadEntryIdsProvider.addEntryIds(from: operation)