mobile-ios/CovidSafe/Feedback/Sources/AsyncAction.swift
2020-05-08 17:49:14 +10:00

72 lines
1.3 KiB
Swift
Executable file
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//Copyright © 2015 Australian Government All rights reserved.
import Foundation
open class AsyncAction: Operation {
fileprivate var _executing = false
fileprivate var _finished = false
override fileprivate(set) open var isExecuting: Bool {
get {
return _executing
}
set {
willChangeValue(forKey: "isExecuting")
_executing = newValue
didChangeValue(forKey: "isExecuting")
}
}
override fileprivate(set) open var isFinished: Bool {
get {
return _finished
}
set {
willChangeValue(forKey: "isFinished")
_finished = newValue
didChangeValue(forKey: "isFinished")
}
}
override open var completionBlock: (() -> Void)? {
set {
super.completionBlock = newValue
}
get {
return {
super.completionBlock?()
self.actionCompleted()
}
}
}
override open var isAsynchronous: Bool {
return true
}
override open func start() {
if isCancelled {
isFinished = true
return
}
isExecuting = true
autoreleasepool {
self.run()
}
}
func run() {
preconditionFailure("This abstract method must be overridden.")
}
func actionCompleted() {
//optional
}
func finishedExecutingOperation() {
isExecuting = false
isFinished = true
}
}