<commit_before>//
//  RAC+Extensions.swift
//  MantleData
//
//  Created by Anders on 14/12/2015.
//  Copyright © 2015 Anders. All rights reserved.
//

import ReactiveCocoa

final public class Queue {
	public static let mainQueue = Queue()

	private(set) public var underlyingQueue: dispatch_queue_t
	public let isMainQueue: Bool

	public init(concurrency: Concurrency, name: String = "") {
		underlyingQueue = dispatch_queue_create(name, concurrency.libdispatchValue)
		dispatch_queue_set_specific(underlyingQueue, &underlyingQueue, &underlyingQueue, nil)
		isMainQueue = false
	}

	internal init() {
		underlyingQueue = dispatch_get_main_queue()
		isMainQueue = true
	}

	public func acquire(@noescape action: () -> Void) {
		if isMainQueue {
			if NSThread.isMainThread() {
				action()
				return
			}
		} else {
			if nil != dispatch_get_specific(&underlyingQueue) {
				action()
				return
			}
		}

		_mantleData_dispatch_sync(underlyingQueue, action)
	}

	public func acquiringFenceWith(@noescape action: () -> Void) {
		_mantleData_dispatch_barrier_sync(underlyingQueue, action)
	}

	public func append(action: () -> Void) {
		dispatch_async(underlyingQueue, action)
	}

	public func appendFenceWith(action: () -> Void) {
		dispatch_barrier_async(underlyingQueue, action)
	}

	public func appendAfter(time: Double, action: () -> Void) {
		let time = dispatch_time(DISPATCH_TIME_NOW, Int64(time * Double(NSEC_PER_SEC)))
		dispatch_after(time, underlyingQueue, action)
	}

	public func suspend() {
		dispatch_suspend(underlyingQueue)
	}

	public func resume() {
		dispatch_resume(underlyingQueue)
	}

	public enum Concurrency {
		case Concurrent
		case Serial

		var libdispatchValue: dispatch_queue_attr_t {
			switch self {
			case .Concurrent: return DISPATCH_QUEUE_CONCURRENT
			case .Serial: return DISPATCH_QUEUE_SERIAL
			}
		}
	}<commit_msg>Extension to `dispatch_queue_t`, replacing the `Queue` class. Renamed a few methods to be inline with the NSManagedObjectContext extension.<commit_after>//
//  RAC+Extensions.swift
//  MantleData
//
//  Created by Anders on 14/12/2015.
//  Copyright © 2015 Anders. All rights reserved.
//

import ReactiveCocoa

public typealias Queue = dispatch_queue_t
public var mainQueue = dispatch_get_main_queue()

extension dispatch_queue_t {
	public func perform<Result>(@noescape action: () -> Result) -> Result {
		var result: Result!
		_mantleData_dispatch_sync(self) {
			result = action()
		}
		return result
	}

	public func performWithBarrier<Result>(@noescape blockingAction: () -> Result) -> Result {
		var result: Result!
		_mantleData_dispatch_barrier_sync(self) {
			result = blockingAction()
		}
		return result
	}

	public func schedule(action: () -> Void) {
		dispatch_async(self, action)
	}

	public func scheduleWithBarrier(blockingAction: () -> Void) {
		dispatch_barrier_async(self, blockingAction)
	}

	public func schedule(after second: NSTimeInterval, action: () -> Void) {
		let time = dispatch_time(DISPATCH_TIME_NOW, Int64(second * Double(NSEC_PER_SEC)))
		dispatch_after(time, self, action)
	}

	public func suspend() {
		dispatch_suspend(self)
	}

	public func resume() {
		dispatch_resume(self)
	}
{'fraction_non_alphanumeric': 0.1021437578814628, 'fraction_numerical': 0.008827238335435058, 'mean_word_length': 4.433219178082192, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '2454518', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1009, 'n_words': 242}