<commit_before>import Foundation
import Alamofire

/// Internal token that can be used to cancel requests
internal final class CancellableToken: Cancellable, CustomDebugStringConvertible {
    let cancelAction: () -> Void
    let request : Request?
    private(set) var isCancelled: Bool = false

    private var lock: OSSpinLock = OS_SPINLOCK_INIT

    func cancel() {
        OSSpinLockLock(&self.lock)
        defer { OSSpinLockUnlock(&self.lock) }
        if self.isCancelled { return }

        self.isCancelled = true
        cancelAction()
    }

    init(action: () -> Void){
        self.cancelAction = action
        self.request = nil
    }

    init(request : Request){
        self.request = request
        self.cancelAction = {
            request.cancel()
        }
    }

    var debugDescription: String {
        if self.request == nil {
            return "Empty Request"
        }

        return request.debugDescription
    }
}

public func DefaultAlamofireManager() -> Manager {
    let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
    configuration.HTTPAdditionalHeaders = Manager.defaultHTTPHeaders

    let manager = Manager(configuration: configuration)
    manager.startRequestsImmediately = false
    return manager
}

public class AlamofireBackend: BackendType {
    let manager: Manager
    let willSendRequest: ((Request, TargetType) -> Request)?

    public init(manager: Manager = DefaultAlamofireManager(), willSendRequest: ((Request, TargetType) -> Request)? = nil) {
        self.manager = manager<commit_msg>[AlamofireBackend] Set manager do not start request immediately in initialize<commit_after>import Foundation
import Alamofire

/// Internal token that can be used to cancel requests
internal final class CancellableToken: Cancellable, CustomDebugStringConvertible {
    let cancelAction: () -> Void
    let request : Request?
    private(set) var isCancelled: Bool = false

    private var lock: OSSpinLock = OS_SPINLOCK_INIT

    func cancel() {
        OSSpinLockLock(&self.lock)
        defer { OSSpinLockUnlock(&self.lock) }
        if self.isCancelled { return }

        self.isCancelled = true
        cancelAction()
    }

    init(action: () -> Void){
        self.cancelAction = action
        self.request = nil
    }

    init(request : Request){
        self.request = request
        self.cancelAction = {
            request.cancel()
        }
    }

    var debugDescription: String {
        if self.request == nil {
            return "Empty Request"
        }

        return request.debugDescription
    }
}

public func DefaultAlamofireManager() -> Manager {
    let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
    configuration.HTTPAdditionalHeaders = Manager.defaultHTTPHeaders

    let manager = Manager(configuration: configuration)
    return manager
}

public class AlamofireBackend: BackendType {
    let manager: Manager
    let willSendRequest: ((Request, TargetType) -> Request)?

    public init(manager: Manager = DefaultAlamofireManager(), willSendRequest: ((Request, TargetType) -> Request)? = nil) {
        manager.startRequestsImmediately = false

        self.manager = manager
{'fraction_non_alphanumeric': 0.0833074292819397, 'fraction_numerical': 0.0, 'mean_word_length': 2.9006060606060604, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '6186229', 'n_tokens_mistral': 857, 'n_tokens_neox': 829, 'n_words': 226}