<commit_before>//
//  Timeout.swift
//  bmap
//
//  Created by <NAME> on 11/25/15.
//  Copyright © 2015 Intrepid. All rights reserved.
//

import Foundation

public class TimeoutOperation : NSOperation {
    private(set) var block: Block?
    let duration: NSTimeInterval
    let queue: dispatch_queue_t
    public init(duration: NSTimeInterval = 30, runQueue: dispatch_queue_t = dispatch_get_main_queue(), block: Block) {
        self.duration = duration
        self.block = block
        self.queue = runQueue
        super.init()
        
        NSOperationQueue().addOperation(self)
    }
    
    override public func main() {
        After(duration, on: queue) { [weak self] in
            if let cancelled = self?.cancelled, let block = self?.block where !cancelled {
                block()
            }
        }
    }
    
    override public func cancel() {
        super.cancel()
        block = nil
    }
}<commit_msg>adding queue arg and brief notes on timeout operation<commit_after>//
//  Timeout.swift
//  bmap
//
//  Created by <NAME> on 11/25/15.
//  Copyright © 2015 Intrepid. All rights reserved.
//

import Foundation

/**
 This classed is used to create a timeout operation that fires 
 after a given amount of time
 
 Setting to `nil` or calling `cancel()` will abort the timeout.
 */
public class TimeoutOperation : NSOperation {
    
    private(set) var block: Block?
    
    private let duration: NSTimeInterval
    private let queue: dispatch_queue_t

    public init(
        duration: NSTimeInterval = 30,
        runQueue: dispatch_queue_t = dispatch_get_main_queue(),
        block: Block,
        timeoutQueue: NSOperationQueue = NSOperationQueue()
        ) {
            
        self.duration = duration
        self.block = block
        self.queue = runQueue
        super.init()
        
        timeoutQueue.addOperation(self)
    }
    
    override public func main() {
        After(duration, on: queue) { [weak self] in
            if let cancelled = self?.cancelled, let block = self?.block where !cancelled {
                block()
            }
        }
    }
    
    override public func cancel() {
        super.cancel()
        block = nil
    }
}
{'fraction_non_alphanumeric': 0.09206349206349207, 'fraction_numerical': 0.010884353741496598, 'mean_word_length': 2.046961325966851, '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': '4255919', 'n_tokens_mistral': 643, 'n_tokens_neox': 610, 'n_words': 191}