<commit_before>//
//  Dispatch.swift
//  Montparnasse
//
//  Created by <NAME> on 15/10/14.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

import Foundation

/// Grand Central Dispatch Queue wrapper
public class DispatchQueue {
    /// Dispatch Priority
    public enum Priority {
        case Background, Default, High, Low
        
        func queue() -> dispatch_queue_t {
            
            var priority:Int = 0
            
            switch (self) {
            case .Background:
                priority = DISPATCH_QUEUE_PRIORITY_BACKGROUND
            case .Default:
                priority = DISPATCH_QUEUE_PRIORITY_DEFAULT
            case .High:
                priority = DISPATCH_QUEUE_PRIORITY_HIGH
            case .Low:
                priority = DISPATCH_QUEUE_PRIORITY_LOW
                
            }
            return dispatch_get_global_queue(priority, 0)
        }
        
    }
    public typealias Delay = dispatch_time_t

    private(set) var queue:dispatch_queue_t
    
    //MARK: Convenient queue
    public class var mainQueue:DispatchQueue {
        return DispatchQueue(queue: dispatch_get_main_queue())
    }

    //MARK: Initializers
    public init( queue q:dispatch_queue_t) {
        queue = q
    }
    public init( priority:Priority) {
        queue = priority.queue()
    }
    public init( backgroundQueueName:String) {
        queue = dispatch_queue_create(backgroundQueueName, nil)
    }

    //MARK: Dispatch function
    public func asyncBlock(block:() -> ()) {
        dispatch_async(queue, block)
    }
    public func syncBlock(block:() -> ()) {
        dispatch_sync(queue, block)
    }
    public func after(delay:Delay,  block:() -> ()) {
        dispatch_after(delay, queue, block)
    }
}

//MARK: Dispatch convenient func
public func once(block:() -> ()) {
    var token : dispatch_once_t = 0
    dispatch_once(&token,block)
}
public func async(block:() -> ()) {
    DispatchQueue.mainQueue.asyncBlock(block)
}
public func sync(block:() -> ()) {
    DispatchQueue.mainQueue.syncBlock(block)
}
public func after(delay:DispatchQueue.Delay,  block:() -> ()) {
    DispatchQueue.mainQueue.after(delay, block:block)
}


<commit_msg>refactoring - use enum instead of class<commit_after>//
//  Dispatch.swift
//  Montparnasse
//
//  Created by <NAME> on 15/10/14.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

import Foundation

/**
A wrapper for Grand Central Dispatch Queue
*/
public enum DispatchQueue {
    /**
    The serial queue associated with the application’s main thread
    */
    case Main
    
    /**
    A system-defined global concurrent queue with a User Interactive quality of service class.
    */
    case UserInteractive
    
    /**
    A system-defined global concurrent queue with a User Initiated quality of service class.
    */
    case UserInitiated
    
    /**
    A system-defined global concurrent queue with a Default quality of service class.
    */
    case Default
    
    /**
    A system-defined global concurrent queue with a Utility quality of service class.
    */
    case Utility
    
    /**
    A system-defined global concurrent queue with a Background quality of service class.
    */
    case Background

    case Concurrent(name:String)
    case Serial(name:String)
    case Custom(queue:dispatch_queue_t)

    
    /**
   
    */
    func queue() -> dispatch_queue_t {
        switch (self) {
        case .Main:
            return dispatch_get_main_queue()
        case .UserInteractive:
            return dispatch_get_global_queue(Int(QOS_CLASS_USER_INTERACTIVE.value), 0)
        case .UserInitiated:
            return dispatch_get_global_queue(Int(QOS_CLASS_USER_INITIATED.value), 0)
        case .Default:
            return dispatch_get_global_queue(Int(QOS_CLASS_DEFAULT.value), 0)
        case .Utility:
            return dispatch_get_global_queue(Int(QOS_CLASS_UTILITY.value), 0)
        case .Background:
            return dispatch_get_global_queue(Int(QOS_CLASS_BACKGROUND.value), 0)
        case .Concurrent(let name):
            return dispatch_queue_create(name,DISPATCH_QUEUE_CONCURRENT)
        case .Serial(let name):
            return dispatch_queue_create(name,DISPATCH_QUEUE_SERIAL)
        case .Custom(let queue):
            return queue
        }
        
    }

    //MARK: Dispatch function
    public func asyncBlock(block:() -> ()) {
        dispatch_async(queue(), block)
    }
    public func syncBlock(block:() -> ()) {
        dispatch_sync(queue(), block)
    }
    public func after(delay:NSTimeInterval,  block:() -> ()) {
        dispatch_after(dispatch_time_t(delay) * dispatch_time_t(NSEC_PER_SEC), queue(), block)
    }
}

//MARK: Dispatch convenient func
public func once(block:() -> ()) {
    var token : dispatch_once_t = 0
    dispatch_once(&token,block)
}
public func async(block:() -> ()) {
    DispatchQueue.Main.asyncBlock(block)
}
public func sync(block:() -> ()) {
    DispatchQueue.Main.syncBlock(block)
}
public func after(delay:NSTimeInterval,  block:() -> ()) {
    DispatchQueue.Main.after(delay, block:block)
}



{'fraction_non_alphanumeric': 0.10207680250783699, 'fraction_numerical': 0.005681818181818182, 'mean_word_length': 2.4101536406145625, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, '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': '7012907', 'n_tokens_mistral': 1540, 'n_tokens_neox': 1482, 'n_words': 361}