2019-09-19 04:56:43 +02:00
|
|
|
//
|
2019-09-23 09:29:53 +02:00
|
|
|
// FeedlyOperation.swift
|
2019-09-19 04:56:43 +02:00
|
|
|
// Account
|
|
|
|
//
|
|
|
|
// Created by Kiel Gillard on 20/9/19.
|
|
|
|
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2019-09-23 09:29:53 +02:00
|
|
|
protocol FeedlyOperationDelegate: class {
|
|
|
|
func feedlyOperation(_ operation: FeedlyOperation, didFailWith error: Error)
|
2019-09-19 04:56:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Abstract class common to all the tasks required to ingest content from Feedly into NetNewsWire.
|
|
|
|
/// Each task should try to have a single responsibility so they can be easily composed with others.
|
2019-09-23 09:29:53 +02:00
|
|
|
class FeedlyOperation: Operation {
|
2019-09-19 04:56:43 +02:00
|
|
|
|
2019-09-23 09:29:53 +02:00
|
|
|
weak var delegate: FeedlyOperationDelegate?
|
2019-09-19 04:56:43 +02:00
|
|
|
|
|
|
|
func didFinish() {
|
2019-10-16 13:12:37 +02:00
|
|
|
assert(Thread.isMainThread)
|
2019-11-06 01:22:10 +01:00
|
|
|
assert(!isFinished, "Finished operation is attempting to finish again.")
|
2019-11-14 21:59:44 +01:00
|
|
|
isExecutingOperation = false
|
|
|
|
isFinishedOperation = true
|
2019-09-19 04:56:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func didFinish(_ error: Error) {
|
2019-10-16 13:12:37 +02:00
|
|
|
assert(Thread.isMainThread)
|
2019-11-06 01:22:10 +01:00
|
|
|
assert(!isFinished, "Finished operation is attempting to finish again.")
|
2019-09-23 09:29:53 +02:00
|
|
|
delegate?.feedlyOperation(self, didFailWith: error)
|
2019-09-19 04:56:43 +02:00
|
|
|
didFinish()
|
|
|
|
}
|
|
|
|
|
|
|
|
override func start() {
|
2019-11-14 21:59:44 +01:00
|
|
|
guard !isCancelled else {
|
|
|
|
isExecutingOperation = false
|
|
|
|
isFinishedOperation = true
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-09-19 04:56:43 +02:00
|
|
|
isExecutingOperation = true
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
self.main()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override var isExecuting: Bool {
|
|
|
|
return isExecutingOperation
|
|
|
|
}
|
|
|
|
|
2019-10-18 23:21:02 +02:00
|
|
|
private var isExecutingOperation = false {
|
2019-09-19 04:56:43 +02:00
|
|
|
willSet {
|
|
|
|
willChangeValue(for: \.isExecuting)
|
|
|
|
}
|
|
|
|
didSet {
|
|
|
|
didChangeValue(for: \.isExecuting)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override var isFinished: Bool {
|
|
|
|
return isFinishedOperation
|
|
|
|
}
|
|
|
|
|
|
|
|
private var isFinishedOperation = false {
|
|
|
|
willSet {
|
|
|
|
willChangeValue(for: \.isFinished)
|
|
|
|
}
|
|
|
|
didSet {
|
|
|
|
didChangeValue(for: \.isFinished)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|