-
-
Save boudhayan/d4716b41c077d0aa05b82f3007c552e8 to your computer and use it in GitHub Desktop.
Revisions
-
calebd renamed this gist
Apr 11, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
calebd revised this gist
Apr 10, 2017 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import Foundation /// Subclasses must implement `execute()` to perform any work and call /// `finish()` when they are done. All `NSOperation` work will be handled /// automatically. open class AsynchronousOperation: Operation { // MARK: - Properties @@ -38,6 +38,10 @@ open class Operation: Foundation.Operation { public final override var isFinished: Bool { return state == .finished } public final override var isAsynchronous: Bool { return true } // MARK: - NSObject -
calebd revised this gist
Dec 8, 2016 . 1 changed file with 6 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,9 @@ open class Operation: Foundation.Operation { // MARK: - Properties private let stateQueue = DispatchQueue( label: "com.calebd.operation.state", attributes: .concurrent) private var rawState = OperationState.ready @@ -18,7 +20,9 @@ open class Operation: Foundation.Operation { } set { willChangeValue(forKey: "state") stateQueue.sync( flags: .barrier, execute: { rawState = newValue }) didChangeValue(forKey: "state") } } -
calebd revised this gist
Dec 8, 2016 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -71,7 +71,9 @@ open class Operation: Foundation.Operation { /// Subclasses must implement this to perform their work and they must not /// call `super`. The default implementation of this function throws an /// exception. open func execute() { fatalError("Subclasses must implement `execute`.") } /// Call this function after any work is done or after a call to `cancel()` /// to move the operation into a completed state. -
calebd revised this gist
Dec 8, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ open class Operation: Foundation.Operation { // MARK: - Properties private let stateQueue = DispatchQueue(label: "com.calebd.operation.state") private var rawState = OperationState.ready -
calebd revised this gist
Dec 8, 2016 . 1 changed file with 76 additions and 49 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,60 +1,87 @@ import Foundation /// An abstract class that makes building simple asynchronous operations easy. /// Subclasses must implement `execute()` to perform any work and call /// `finish()` when they are done. All `NSOperation` work will be handled /// automatically. open class Operation: Foundation.Operation { // MARK: - Properties private let stateQueue = DispatchQueue(label: "com.courtneycircle.radiant.operation.state") private var rawState = OperationState.ready @objc private dynamic var state: OperationState { get { return stateQueue.sync(execute: { rawState }) } set { willChangeValue(forKey: "state") stateQueue.sync(execute: { rawState = newValue }) didChangeValue(forKey: "state") } } public final override var isReady: Bool { return state == .ready && super.isReady } public final override var isExecuting: Bool { return state == .executing } public final override var isFinished: Bool { return state == .finished } // MARK: - NSObject @objc private dynamic class func keyPathsForValuesAffectingIsReady() -> Set<String> { return ["state"] } @objc private dynamic class func keyPathsForValuesAffectingIsExecuting() -> Set<String> { return ["state"] } @objc private dynamic class func keyPathsForValuesAffectingIsFinished() -> Set<String> { return ["state"] } // MARK: - Foundation.Operation public override final func start() { super.start() if isCancelled { finish() return } state = .executing execute() } // MARK: - Public /// Subclasses must implement this to perform their work and they must not /// call `super`. The default implementation of this function throws an /// exception. open func execute() {} /// Call this function after any work is done or after a call to `cancel()` /// to move the operation into a completed state. public final func finish() { state = .finished } } @objc private enum OperationState: Int { case ready case executing case finished } -
calebd revised this gist
Mar 3, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -42,7 +42,7 @@ class ConcurrentOperation: NSOperation { // MARK: - NSOperation override var ready: Bool { return super.ready && state == .Ready } override var executing: Bool { -
calebd revised this gist
Mar 3, 2015 . 1 changed file with 1 addition and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,7 +28,7 @@ class ConcurrentOperation: NSOperation { // MARK: - Properties var state = State.Ready { willSet { willChangeValueForKey(newValue.keyPath()) willChangeValueForKey(state.keyPath()) @@ -39,13 +39,6 @@ class ConcurrentOperation: NSOperation { } } // MARK: - NSOperation override var ready: Bool { -
calebd revised this gist
Jul 18, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -64,4 +64,4 @@ class ConcurrentOperation: NSOperation { return true } } -
calebd revised this gist
Jul 18, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -60,7 +60,7 @@ class ConcurrentOperation: NSOperation { return state == .Finished } override var asynchronous: Bool { return true } -
calebd renamed this gist
Jul 7, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ // // Created by Caleb Davenport on 7/7/14. // // Learn more at http://blog.calebd.me/swift-concurrent-operations // import Foundation -
calebd revised this gist
Jul 7, 2014 . 1 changed file with 6 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ // // ConcurrentOperation.swift // // Created by Caleb Davenport on 7/7/14. // @@ -8,7 +8,7 @@ import Foundation class ConcurrentOperation: NSOperation { // MARK: - Types @@ -60,4 +60,8 @@ class Operation: NSOperation { return state == .Finished } override var concurrent: Bool { return true } } -
calebd created this gist
Jul 7, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,63 @@ // // Operation.swift // // Created by Caleb Davenport on 7/7/14. // // Learn more at <link> // import Foundation class Operation: NSOperation { // MARK: - Types enum State { case Ready, Executing, Finished func keyPath() -> String { switch self { case Ready: return "isReady" case Executing: return "isExecuting" case Finished: return "isFinished" } } } // MARK: - Properties var state: State { willSet { willChangeValueForKey(newValue.keyPath()) willChangeValueForKey(state.keyPath()) } didSet { didChangeValueForKey(oldValue.keyPath()) didChangeValueForKey(state.keyPath()) } } // MARK: - Initializers init() { state = State.Ready super.init() } // MARK: - NSOperation override var ready: Bool { return state == .Ready } override var executing: Bool { return state == .Executing } override var finished: Bool { return state == .Finished } }