<commit_before>//
//  Cadmium+PromiseKit.swift
//  CadmiumPromiseExample
//
//  Created by <NAME> on 5/13/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
import PromiseKit


public enum CdPromiseError : Error {
    case notAvailableInCurrentContext(CdManagedObject?)
}

public extension Cd {
    
    /** Allows you to perform a standard Cadmium transaction as a Promise */
    @discardableResult public class func transact<U>(_ serial: Bool? = nil, on serialQueue: DispatchQueue? = nil, operation: @escaping (Void) throws -> U) -> Promise<U> {
        return Promise { fulfill, reject in
            DispatchQueue.global(qos: .default).async {
                var result: U!
                var error: Error?
                Cd.transactAndWait(serial: serial, on: serialQueue) {
                    do {
                        result = try operation()
                    } catch let _error {
                        error = _error
                    }
                }
                if let error = error {
                    reject(error)
                } else {
                    fulfill(result)
                }
            }
        }
    }
    <commit_msg>remove void from promisekit ext<commit_after>//
//  Cadmium+PromiseKit.swift
//  CadmiumPromiseExample
//
//  Created by <NAME> on 5/13/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
import PromiseKit


public enum CdPromiseError : Error {
    case notAvailableInCurrentContext(CdManagedObject?)
}

public extension Cd {
    
    /** Allows you to perform a standard Cadmium transaction as a Promise */
    @discardableResult public class func transact<U>(_ serial: Bool? = nil, on serialQueue: DispatchQueue? = nil, operation: @escaping () throws -> U) -> Promise<U> {
        return Promise { fulfill, reject in
            DispatchQueue.global(qos: .default).async {
                var result: U!
                var error: Error?
                Cd.transactAndWait(serial: serial, on: serialQueue) {
                    do {
                        result = try operation()
                    } catch let _error {
                        error = _error
                    }
                }
                if let error = error {
                    reject(error)
                } else {
                    fulfill(result)
                }
            }
        }
    }
    
{'fraction_non_alphanumeric': 0.08782104391052195, 'fraction_numerical': 0.007456503728251864, 'mean_word_length': 1.4718526100307063, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '4432350', 'n_tokens_mistral': 660, 'n_tokens_neox': 600, 'n_words': 183}