<commit_before>//
//  AsynchronousOperation.swift
//  BartlebysCore
//
//  Created by <NAME> on 06/06/2018.
//  Copyright © 2018 Bartleby. All rights reserved.
//

import Foundation


// An Operation that can be used to perform Asynchronous Tasks.
// Usage
// 1- You should override this operation
// 2- Override the main method and call `self.state = .finished` on completion
//     override func main () {
//         super.main()
//         if self.isCancelled {
//              return
//         }
//         self.myAsyncStuff(from: self.url, onSuccess: { (...) in
//             self.state = .finished
//         }
//
open class AsynchronousOperation: Operation {

    override open var isAsynchronous: Bool { return true }
    override open var isExecuting: Bool { return self.state == .executing }
    override open var isFinished: Bool { return self.state == .finished }

    public var state = State.ready {
        willSet {
            self.willChangeValue(forKey: self.state.keyPath)
            self.willChangeValue(forKey: newValue.keyPath)
        }
        didSet {
            self.didChangeValue(forKey: self.state.keyPath)
            self.didChangeValue(forKey: oldValue.keyPath)
        }
    }

    public enum State: String {
        case ready = "Ready"
        case executing = "Executing"
        case finished = "Finished"
        fileprivate var keyPath: String { return "is" + self.rawValue }
    }
<commit_msg>AsynchronousOperation sync on main states changes<commit_after>//
//  AsynchronousOperation.swift
//  BartlebysCore
//
//  Created by <NAME> on 06/06/2018.
//  Copyright © 2018 Bartleby. All rights reserved.
//

import Foundation


// An Operation that can be used to perform Asynchronous Tasks.
// Usage
// 1- You should override this operation
// 2- Override the main method and call `self.state = .finished` on completion
//     override func main () {
//         super.main()
//         if self.isCancelled {
//              return
//         }
//         self.myAsyncStuff(from: self.url, onSuccess: { (...) in
//             self.state = .finished
//         }
//
open class AsynchronousOperation: Operation {

    override open var isAsynchronous: Bool { return true }
    override open var isExecuting: Bool { return self.state == .executing }
    override open var isFinished: Bool { return self.state == .finished }

    public var state = State.ready {
        willSet {
            syncOnMain{
                self.willChangeValue(forKey: self.state.keyPath)
                self.willChangeValue(forKey: newValue.keyPath)
            }
        }
        didSet {
            syncOnMain{
                self.didChangeValue(forKey: self.state.keyPath)
                self.didChangeValue(forKey: oldValue.keyPath)
            }
        }
    }

    public enum State: String {
        case ready = "Ready"
        case executing = "Executing"
        case finished = "Finished"
        fileprivate var keyPath: String { return "is" + self.rawValue }
    }

{'fraction_non_alphanumeric': 0.10312707917498337, 'fraction_numerical': 0.009314703925482368, 'mean_word_length': 1.989065606361829, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '369916', 'n_tokens_mistral': 887, 'n_tokens_neox': 838, 'n_words': 245}