<commit_before>//
//  FutureKit+Parse.swift
//  whereabout
//
//  Created by Стас on 13/07/15.
//  Copyright (c) 2015 Limehat. All rights reserved.
//

import Foundation
import Parse


extension PFQuery {
    func findObjectsInFuture() -> Future<[AnyObject]> {
        return self.findObjectsInFuture(.Primary)
    }
    
    func findObjectsInFuture(executor:Executor) -> Future<[AnyObject]> {
        let promise = Promise<[AnyObject]>()
        executor.execute {
            self.findObjectsInBackgroundWithBlock({ (results, error) in
                if error == nil && results != nil {
                    promise.completeWithSuccess(results!)
                }
                else if error != nil {
                    promise.completeWithFail(error!)
                }
                else {
                    promise.completeWithFail("Some error")
                }
            })
        }
        return promise.future
    }
}<commit_msg>added several methods for Parse integration<commit_after>//
//  FutureKit+Parse.swift
//  whereabout
//
//  Created by Стас on 13/07/15.
//  Copyright (c) 2015 Limehat. All rights reserved.
//

import Foundation
import Parse


extension PFQuery {
    func findObjectsInFuture() -> Future<[AnyObject]> {
        return self.findObjectsInFuture(.Primary)
    }
    
    func findObjectsInFuture(executor:Executor) -> Future<[AnyObject]> {
        let promise = Promise<[AnyObject]>()
        executor.execute {
            self.findObjectsInBackgroundWithBlock({ (results, error) in
                if error == nil && results != nil {
                    promise.completeWithSuccess(results!)
                }
                else if error != nil {
                    promise.completeWithFail(error!)
                }
                else {
                    promise.completeWithFail("Some error")
                }
            })
        }
        return promise.future
    }
}

extension PFObject {
    func saveInBackgroundInFuture() -> Future<Bool> {
        return self.saveInBackgroundInFuture(.Primary)
    }
    
    func saveInBackgroundInFuture(executor:Executor) -> Future<Bool> {
        let promise = Promise<Bool>()
        executor.execute {
            self.saveInBackgroundWithBlock { (success, error) in
                if error == nil && success {
                    promise.completeWithSuccess(success)
                }
                else if error != nil {
                    promise.completeWithFail(error!)
                }
                else {
                    promise.completeWithFail("Some error")
                }
            }
        }
        return promise.future
    }
    
    func fetchIfNeededInFuture() -> Future<PFObject> {
        return self.fetchIfNeededInFuture(.Primary)
    }
    
    func fetchIfNeededInFuture(executor:Executor) -> Future<PFObject> {
        let promise = Promise<PFObject>()
        executor.execute {
            self.fetchIfNeededInBackgroundWithBlock({ (object, error) -> Void in
                if error == nil && object != nil {
                    promise.completeWithSuccess(object!)
                }
                else if error != nil {
                    promise.completeWithFail(error!)
                }
                else {
                    promise.completeWithFail("Some error")
                }
            })
        }
        return promise.future
    }
    
    class func saveAllInBackgroundInFuture(objects: [AnyObject]) -> Future<Bool> {
        return PFObject.saveAllInBackgroundInFuture(.Primary, objects:objects)
    }
    
    class func saveAllInBackgroundInFuture(executor:Executor, objects: [AnyObject]) -> Future<Bool> {
        let promise = Promise<Bool>()
        executor.execute {
            PFObject.saveAllInBackground(objects) { (success, error) in
                if error == nil && success {
                    promise.completeWithSuccess(success)
                }
                else if error != nil {
                    promise.completeWithFail(error!)
                }
                else {
                    promise.completeWithFail("Some error")
                }
            }
        }
        return promise.future
    }
}
{'fraction_non_alphanumeric': 0.0944022770398482, 'fraction_numerical': 0.004743833017077799, 'mean_word_length': 1.5511191772534785, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 29, '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': '6678705', 'n_tokens_mistral': 1099, 'n_tokens_neox': 1034, 'n_words': 214}